List of HTML Self-Closing Tags
Here is a complete list of self-closing tags for HTML5. These are called void-elements in HTML spec.
<area />
<base />
<br />
<col />
<embed />
<hr />
<img />
<input />
<link />
<meta />
<param />
<source />
<track />
<wbr />
<command />
(obsolete)<keygen />
(obsolete)<menuitem />
(obsolete)<frame />
(obsolete)
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 recommend to always add the slash. Because, it provides a visual clue of non-closing tags.
XHTML Supports Self-Closing Syntax for All Tags
In XML/XHTML, any tag can be self-closed by the ending slash <… />
.
When you test XML, 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.
Reference
