Void elements
suggest changeHTML 4.01/XHTML 1.0 Strict includes the following void elements:
area- clickable, defined area in an imagebase- specifies a base URL for resolving relative URLsbr- line breakcol- column in a tablehr- horizontal rule (line)img- imageinput- field where users enter datalink- links an external resource to the documentmeta- provides information about the documentparam- defines parameters for plugins
HTML5 includes those elements and also:
embed- embeds external contentsource- specifies media sources forpicture,audio, andvideoelementstrack- timed text foraudioandvideowbr- a line-break opportunity
Early HTML5 drafts also included command and keygen. Both are obsolete and must not be used.
The example below does not include void elements:
<div>
<a href="http://stackoverflow.com/">
<h3>Click here to visit <i>Stack Overflow!</i></h3>
</a>
<button onclick="alert('Hello!');">Say Hello!</button>
<p>My favorite language is <b>HTML</b>. Here are my others:</p>
<ol>
<li>CSS</li>
<li>JavaScript</li>
<li>PHP</li>
</ol>
</div>
Notice how every element has an opening tag, a closing tag, and text or other elements inside the opening and closing tags. Void elements, however, are shown in the example below:
<img src="https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-icon.png" />
<br>
<hr>
<input type="number" placeholder="Enter your favorite number">
Each of these void elements has only a start tag. In HTML, a trailing slash (<img ... />) is optional on every void element, not just img, and it does not change how the tag is parsed. A closing tag is not allowed.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents