HTML5

void elements

Joost van Meeteren


Links

Blog.teamtreehouse.com - To Close or Not To Close Tags in HTML5.

Tiffanybbrown.com - HTML5 does NOT allow "self-closing" tags ... on non-void elements, at least.

Xahlee.info - List of HTML Self-Closing Tags.

W3schools - HTML Tags Ordered Alphabetically.


Introduction

The elements <br> or <img> do not have closing tags. A tag like <p> does: <p> [ content ] </p>.

Elements without closing tags are 'empty' because they do not contain content (text). Empty elements only contain attributes like src and alt: <img src="image.png" alt="image">.

HTML5 allows two ways of notation: <br> and <br />. I prefer the last notation. So I can see easily the difference between tags with and without closing tags in het body section.
Note. On the other hand I use the first notation in the head section: <meta charset="utf-8">, <link href="icon.png" rel="icon" type="image/png">. This way I emphasize the contrast between the head and body sections.

HTML5 | HTML4 | XHTML. The slash in the elements without closing tags is optional in HTML5, in HTML4 officially not allowed but practically accepted, in XHTML the slash is required.

The elements without closing tags are also called self-closing or empty or void elements.


Examples

Some of the examples below are widely used and therefore well known (see <br />, <hr />, <img />), others are rarely used and less known (see <source /> and <wbr />).

<area> or <area />: HTML <area> Tag.

<base> or <base />: HTML <base> Tag.

<br> or <br />: HTML <br> Tag.

<col> or <col />: HTML <col> Tag.

<embed> or embed />: HTML <embed> Tag.

<hr> or <hr />: HTML <hr> Tag.

<img> or <img />: HTML <img> Tag.

<input> or <input />: HTML <input> Tag.

<keygen> or <keygen />: HTML <keygen> Tag.

<link> or <link />: HTML <link> Tag.

<meta> or <meta />: HTML <meta> Tag.

<param> or <param />: HTML <param> Tag.

<source> or <source />: HTML <source> Tag.

<track> or <track />: HTML <track> Tag.

<wbr> or <wbr />: HTML <wbr> Tag.


Joost van Meeteren Websites
2002-2024 © Joost van Meeteren, Bennekom NL
Laatste update website: woensdag 24 april 2024