Search This Blog

Tuesday, 9 September 2014

(HTML) elements

HTML Elements

An HTML element is everything from the start tag to the end tag:

The start tag is the opening tag and end tag is closeing 
tag.

Nested HTML Elements

Most HTML elements can be nested (elements can contain elements).
All HTML documents consist of nested HTML elements.
This example contains 3 HTML elements:

Example

<!DOCTYPE html>
<html>

<body>
  <p>This is my first paragraph.</p>
</body>

</html>


HTML Example Explained

The <p> element:
<p>This is my first paragraph.</p>
The <p> element defines a paragraph. It has a start tag <p> and an end tag </p>.
The element content is: This is my first paragraph.
The <body> element:
<body>
  <p>This is my first paragraph.</p>
</body>
The <body> element defines the document body. It has a start tag <body> and an end tag </body>.
The element content is another HTML element (a <p> element).
The <html> element:
<html>

<body>
  <p>This is my first paragraph.</p>
</body>

</html>
The <html> element defines the whole document. It has a start tag <html> and an end tag </html>.
The element content is another HTML element (the <body> element).

Don't Forget the End Tag

Some HTML elements will display correctly, even if you forget the end tag:

Example

<html>

<body>
  <p>This is a paragraph
  <p>This is a paragraph
</body>

</html>
The example above works in all browsers, because the closing tag is considered optional.
Never rely on this. It might produce unexpected results and/or errors if you forget the end tag.

Empty HTML Elements

HTML elements with no content are called empty elements.
<br> is an empty element without a closing tag (the <br> tag defines a line break).
You can close the empty element in the opening tag like this: <br />.

HTML Tip: Use Lowercase Tags

HTML tags are not case sensitive: <P> means the same as <p>.
The HTML5 standard does not require lowercase tags, but W3C recommends lowercase in HTML4, and demandslowercase for stricter document types like XHTML.

No comments:

Post a Comment