What is a void or empty element in HTML5?




A void element is any element that can not, by definition, have any content in between the start and end tags, but the only type of data that void elements are allowed to have are attributes. Some examples of void elements that you are probably already familiar with include the img (image), br (break), hr (horizontal rule), and meta tags. Of course, all of the tags that we mentioned can have attributes, but the reason they are void elements is that you will never see any content in between a start and end tag for a void element – so something like www.somesite.com/animage.png, or some meta info here would be invalid and would not make any sense anyways since you can put all of that information in the atrributes of those tags.

Void elements versus element without any content

One thing that may confuse people is that just because an element does not have any content in a specific example does not make it a void element. So, for example, if you have a paragraph tag without any content inside it like this: <p></p>, then that does not mean the p tag is a void element – it just means that the p tag does not have any content in this specific scenario. The p tag is still a non-void element, because it can have content in between it’s start and end tags. Remember that a void element is an element that can not have any content in between the start and end tags under any scenario – and just because an element doesn’t have content in one scenario (like our example p tag) does not make that element a void element.

List of void elements in HTML

Here’s a complete list of void elements in HTML:

area, base, br, col, command, embed, hr, img, input,
keygen, link, meta, param, source, track, wbr

Hiring? Job Hunting? Post a JOB or your RESUME on our JOB BOARD >>

Subscribe to our newsletter for more free interview questions.

  • Alag Janehe

    Great answer

  • jyoti

    Hi i need web development interview questions & answers..