Jump to content

What is an HTML empty element?


RayL

Recommended Posts

We're told that <br> is an empty element and it has no end tag.

Is "<p></p>" an empty element?  It has no content ("stuff between the start/end tags").

Is it true that "empty elements" have no end tag?

If it is, then why does "<p></p>" have an end tag, given it has no content and is therefore an empty tag?

 

Link to comment
Share on other sites

An empty element is one which has no purpose for the content between the tags. Empty elements do not need an end tag and shouldn't have one.

While <p></p> is empty, it's not considered an "empty element" because when there is something between the tags, it's meaningful.

This is not common practice, but specific elements such as <p> and <li> actually can work without a closing tag. This is because the browser know that the content of a <p> element must end as soon as it runs into another block element or when its parent ends.

Link to comment
Share on other sites

  • 4 months later...

Element without an enclosing tag is known as an empty element. The closing tags cannot be added to empty elements. No child nodes exist for empty elements. As a result, empty tags are self-closing or void in nature, and are not container tags. For input, meta-data, area, etc., empty elements can be used to embed images, lists, breaks, horizontal lines, hyperlinks, etc. For instance, <p> tag had a closing tag hence it was not an empty element.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...