HTML Elements
- Previous Page HTML Basics
- Next Page HTML Attributes
An HTML document is defined by HTML elements.
HTML Elements
HTML elements refer to all the code from the start tag (start tag) to the end tag (end tag).
Start tag | Element content | End tag |
---|---|---|
<p> | This is a paragraph | </p> |
<a href="default.htm" > | This is a link | </a> |
<br /> |
Note:Start tags are often called opening tags (opening tag), and end tags are often called closing tags (closing tag).
HTML element syntax
- HTML elements areStart tagStarting
- HTML elements areEnd tagTermination
- Element contentIt is the content between the start tag and the end tag
- Certain HTML elements haveEmpty content (empty content)
- Empty elementsClosed in the start tag(ending with the end of the start tag)
- Most HTML elements can haveAttributes
Tip:You will learn more about attributes in the next chapter of this tutorial.
Nested HTML elements
Most HTML elements can be nested (can contain other HTML elements).
An HTML document is composed of nested HTML elements.
HTML document instance
<html> <body> <p>This is my first paragraph.</p> </body> </html>
The above example contains three HTML elements.
HTML instance explanation
<p> element:
<p>This is my 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 my first paragraph.
<body> element:
<body> <p>This is my first paragraph.</p> </body>
<body> element defines the main content of the HTML document.
This element has a start tag <body>, and an end tag </body>.
The content of the element is another HTML element (p element).
<html> element:
<html> <body> <p>This is my first paragraph.</p> </body> </html>
The <html> element defines the entire HTML document.
This element has a start tag <html>, and an end tag </html>.
Element content is another HTML element (body element).
Do not forget the closing tag
Even if you forget to use the closing tag, most browsers will correctly display HTML:
<p>This is a paragraph <p>This is a paragraph
The above examples work in most browsers, but do not rely on this practice. Forgetting to use closing tags can result in unpredictable results or errors.
Note:Future versions of HTML will not allow the omission of closing tags.
Empty HTML Elements
HTML elements without content are called empty elements. Empty elements are closed in the start tag.
<br> is an empty element without a closing tag (the <br> tag defines a line break).
In XHTML, XML, and future versions of HTML, all elements must be closed.
Adding a slash in the start tag, such as <br />, is the correct method to close empty elements, which HTML, XHTML, and XML all accept this method.
Even though <br> is valid in all browsers, using <br /> is actually a longer-term safeguard.
HTML Tip: Use lowercase tags
HTML tags are case-insensitive: <P> is equivalent to <p>. Many websites use uppercase HTML tags.
CodeW3C.com uses lowercase tags because the World Wide Web Consortium (W3C) in HTML 4RecommendedUse lowercase, and in the future (X)HTML versionsEnforceUse lowercase.
- Previous Page HTML Basics
- Next Page HTML Attributes