From http://www.w3schools.com (Copyright Refsnes Data)

HTML Elements

Previous Next

HTML Elements

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

Start tag Element content End tag
<p> This is a paragraph </p>
<a href="default.htm" > This is a link </a>


HTML Element Syntax

Note: The start tag can have additional information (attributes). See next chapter.


Nested HTML Elements

Most HTML elements can be nested (can contain other HTML elements).

Most HTML documents consist of nested HTML elements.


HTML Document Example

<html>

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

</html>

The example above contains 3 HTML elements:

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

The <p> element defines a paragraph in the HTML document:
The element has a start tag <p> and an end tag </p>
The element content is: This is my first paragraph

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

The <body> element defines the body of the HTML document
The element has a start tag <body> and an end tag </body>
The element content is another element (a paragraph)

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

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


Empty HTML Elements

HTML elements without content are called empty elements. Empty elements have no end tag.

<br /> is an empty element without a closing tag.

In XHTML, XML, and future versions of HTML, all elements must be closed.

Adding a slash to the start tag, like <br />, is the proper way of closing empty elements, accepted by HTML, XHTML and XML.

Even if <br> works in all browsers, writing <br /> instead is more future proof.


HTML Tip - Lowercase Tags

HTML tags are not case sensitive: <P> means the same as <p>. Plenty of web sites use uppercase HTML tags in their pages.

W3Schools use lowercase tags because the World Wide Web Consortium (W3C) recommends lowercase in HTML 4, and demands lowercase tags in newer versions of (X)HTML.


Previous Next

From http://www.w3schools.com (Copyright Refsnes Data)