Open In App

Is container tag same as the empty tag in HTML? If not, why ?

In this article, we will see the container tag & empty tag in HTML, along with knowing how they’re different from each other. The Container tag is not the same as the empty tag & these are two different categories of tags used in HTML.

Container tag: This tag contains 3 parts, namely, the opening tag, content that will be displayed in the browser & the closing tag. If we forget to add the closing tag then the browser will continue to implement the effect of that opening tag on the content inside of that tag. This will deform the structure of the overall webpage.



Syntax:

<Tag_Name> Content </Tag_Name>

List of commonly used Container Tags:



These are also some container tags that are generally used inside an HTML document.

Example: The example below demonstrates the use of container tags in HTML.




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta name="viewport" content=
        "width=device-width, initial-scale=1.0">
  
    <title>
        Container tag & Empty tag in HTML
    </title>
</head>
  
<body>
    <h2>Welcome To GFG</h2>
    <h3>
        Here are some common container 
        tags used in this code:
    </h3>
  
    <p>Hey! This is a paragraph.</p>
  
    <h3>Below is an description list:</h3>
    <dl>
        <dt>GeeksforGeeks</dt>
        <dd>
            GeeksforGeeks is an online learning
            platform for geeks around the globe.
        </dd>
        <dt>Notebook</dt>
        <dd>
            Notebook is a collection of pages
            (plane or linear) that is used to
            make notes of some important things.
        </dd>
    </dl>
    <button>Click Me!</button>
</body>
  
</html>

Output:

Empty Tags: Empty tags are the tags that only contain the opening tags, they do not have any closing tag. Hence they don’t affect the webpage if we forget to close any empty tag.

Syntax:

<Tag_Name>

Here are some empty tags that are generally used in HTML documents:

Example: The below example illustrates the use of the empty tags in HTML.




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta name="viewport" content=
        "width=device-width, initial-scale=1.0">
    <title>
        Container tag & Empty tag in HTML
    </title>
</head>
  
<body>
    <h2>Welcome To GFG</h2>
    <h3>
        Here are some common empty 
        tags used in this code:
    </h3>
  
    <p>Hey! This is a paragraph.</p>
  
    <br>
    <hr>
    <img src=
        alt="GFG_logo"
        height="300px" width="300px">
</body>
  
</html>

Output:

S. No.

Container Tags

Empty Tags

1.

It contains the opening tag, content, & the closing tag.

It has only the opening tag, & do not have any end tag.

2.

Container tags may contain the empty tag inside in it.
Eg.: <p><br></p>.

Empty tags do not contains any tag, it use only attributes inside in it.
Eg: <img src=”” alt=””>.

3.

Container tags can be used to define the behavior of text inside in it.

Empty tag do not have any text content inside in it.

4.

The nesting of the tags can be possible in this case.

The nesting of tags is not possible.


Article Tags :