HTML Element

HTML documents are defined by HTML elements.

HTML Elements

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

*The opening tag is often called the opening tag, and the end tag is often called the closing tag .

HTML Element Syntax

  • HTML element to start tag start

  • HTML elements are terminated by closing tags

  • The content of the element is the content between the start tag and the end tag

  • Some HTML elements have empty content

  • The empty element is closed in the opening tag (ends with the end of the opening tag)

  • Most HTML elements can have attributes

Note: You will learn more about attributes in the next chapter of this tutorial.

Nested HTML Elements

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

HTML documents are composed of HTML elements nested within each other.

HTML Document Example

<!DOCTYPE html>
    <p>This is the first paragraph. 

The above example contains three HTML elements.

HTML Instance Analysis

<p> element:

<p>This is the first paragraph. </p>

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

<body> element:

  <p>This is the first paragraph. 

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

<html> element:

    <p>This is the first paragraph. </p>

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

Don't Forget the Closing Tag

Even if you forget to use the closing tag, most browsers will display the HTML correctly:

<p>This is a paragraph.
<p>This is a paragraph.

The above example can also be displayed normally in the browser, because the closing tag is optional.

But don't rely on this approach. Forgetting to use the end tag can produce unpredictable results or errors.

HTML Empty Element

HTML elements with no content are called empty elements. The empty element is closed in the opening tag.

<br> is an empty element without closing tag (<br> tag defines line break).

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

Adding a slash in the opening tag, such as <br />, is the correct way to close empty elements. HTML, XHTML, and XML all accept this method.

Even though <br> is effective in all browsers, using <br /> is actually a longer-term guarantee.

HTML Tip: Use Lowercase Tags

HTML tags are not case sensitive: <P> is equivalent to <p>. Many websites use uppercase HTML tags.

The uses lowercase tags, because the World Wide Web Consortium (W3C) recommends lowercase in HTML 4 , and will force lowercase in future (X)HTML versions .