HOME C C++ PYTHON JAVA HTML CSS JAVASCRIPT BOOTSTRAP JQUERY REACT PHP SQL AJAX JSON DATA SCIENCE AI

HTML Elements

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

<tagname>Content goes here...</tagname>

Examples of some HTML elements:

<h1>My First Heading</h1>
<p>My first paragraph.</p>




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:

Example

    
<p>This is a <br> paragraph with a line break.</p>
                

You can click on above box to edit the code and run again.

Output

This is a
paragraph with a line break.