2012-03-23

List of HTML Self-Closing Tags

Perm URL with updates: http://xahlee.org/js/html5_non-closing_tag.html

, 2012-03-23

This page is a list of HTML elements that does not have a closing tag. They are sometimes called {self-closing, empty, void, singleton} tag. Here's a complete list for HTML5:

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

The space before the slash is optional.

Is the Ending Slash Optional?

  • HTML5: the slash is optional.
  • HTML4: the slash is technically invalid. However, it's accepted by W3C's HTML validator.
  • XHTML: The slash is REQUIRED.

I'd recommend to always add the slash. Because, it provides a visual clue of non-closing tags. It's also technically superior, because if you write scripts to check your HTML, you don't need a lookup table to check which tags doesn't need to be closed.

XHTML Supports Self-Closing Syntax for All Tags

In XML/XHTML, every tag can be self-closed by the ending slash <… />. When you test it, you have to make sure the server is sending the correct Internet media type as XHTML (e.g. application/xhtml+xml), otherwise browsers will treat it as HTML, regardless of the DOCTYPE in your file.

I do no recommend self-closing for normal tags.

References

Back to HTML5 Tags.