HTML Elements
Start tag | content | End tag |
---|---|---|
<h1> | This is heading content. | </h1> |
<p> | This is paragraph content. | </p> |
</br> |
So here <p>....</p> is an HTML element, <h1>...</h1> is another HTML element.
There
are some HTML elements which don't need to be closed, such as </img>, </hr> and
</br> elements. These are known as void elements.
Nested HTML Elements
HTML elements can be nested (this means that elements can contain other elements).
All HTML documents consist of nested HTML elements.
The following example contains four HTML elements (<html>, <body>, <h1> and <p>
):
Example
<!DOCTYPE html> <html> <head> <title>Nested Elements</title> </head> <body> <h1>This is <i>italic</i> heading</h1> <p>This is <u>underlined</u> paragraph</p> </body> </html>You can click on above box to edit the code and run again.
Output
This is italic heading
This is underlined paragraph
Empty HTML Elements
HTML elements with no content are called empty elements.
The <br> tag defines a line break, and is an empty element without a closing tag: