What are Empty Tags in HTML?
The HTML consists of several elements and their associated tags to represent some corresponding view on the screen. As you might know from the concept of the Document Object Model in HTML, the entire HTML Document can be represented in a tree structure where each node corresponds to an element, and they can have their attributes as well as child nodes. But not every HTML element can have a child node, and those all are called Empty Elements.
Although if we try to embed content in the empty element, HTML will not stop rendering it, the HTML parses it in a way that nested content gets positioned at the same level just after that empty element in DOM, but it is not a good practice because some framework, library, etc. might throw an error in this situation.
List of Empty Elements used in HTML
Element | Description |
---|---|
img | It accepts a source link of the image and some other attributes like height, width, etc., and is used to embed the image in the HTML Document. |
br | The term br is an abbreviation for a break. It introduces a line break in the document. |
hr | The horizontal rule is used to introduce a graphical line in the HTML document. It is also called a thematic break. Follow this. |
area | The area element is used inside the image map. It defines some particular clickable areas for the image, which further may lead the user to a different link. |
embed | The embed element is used as a container to display any external resource like image, video, plugin, etc. |
input | This element is used to receive input from the user. |
meta | We write this element in the head tag of the document. It is used to specify some metadata (information) about the page. |
source | The source element specifies the media element for the picture, video, or audio element. |
col | It is used inside the colgroup element of tables in HTML and specifies the common properties of columns, ex-style. |
link | It establishes a link or association between some external resource and an HTML document. It is generally used inside the head tag. |
Examples
1. img element
Output:
2. br and hr element
Output:
3. input element
Output:
4. embed element
Output:
Conclusion
- In this article, we have discussed the empty elements of HTML.
- Some examples of empty tags are img, embed, area, meta, link, etc.
- The empty elements are those elements of HTML that cannot have some content like text or child element inside them.
- There is no need to specify the closing tag, and the opening tag should end with /> instead of >. The proper syntax to write these elements is <tagname attributes="values"..... />.