HTML | Elements

HTML element is the collection of start and end tag with the content inserted in between them.

Syntax:

<tagname > Contents... </tagname>

Example:



filter_none

edit
close

play_arrow

link
brightness_4
code

<!-- HTML code to illustrate HTML elements -->
<!DOCTYPE html>
<html>
    <head>
        <title>HTML Elements</title>
    </head>
      
    <body>
        <p>Welcome to GeeksforGeeks!</p>
    </body>
</html>

chevron_right


Output:

Welcome to GeeksforGeeks!

Nested HTML Elements: The HTML element is use inside the another HTML Element is called nested HTML elements.

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
    <head>
        <title>HTML Elements</title>
    </head>
      
    <body style = "text-align:center">
        <h1>GeeksforGeeks</h1>
        <p>Computer science portal</p>
    </body>
</html>                    

chevron_right


Output:

Explanation: In the above example, <html> tag contains the <head> and <body>. The <head< and <body> tag contains another elements so it is called nested element.

Necessary to add end tag: It is necessary to add end tag of element. Otherwise the displayed content may not be display correctly.

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
    <head>
        <title>HTML Elements</title>
    </head>
      
    <body>
          
        <!-- h1 tag does not contains
        end tag -->
        <h1>GeeksforGeeks    
          
        <!-- p tag does not contains
        end tag -->
        <p>Computer science portal
    </body>
</html>                    

chevron_right


Example:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.