Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

HTML concept: void-elements

Void elements are a closed HTML set: they accept no children and have no end tags in HTML syntax.

Version: WHATWG HTML Living Standard; index snapshot date recorded separately

Syntax

<area> <base> <br> <col> <embed> <hr> <img> <input> <link> <meta> <source> <track> <wbr>

The set is area, base, br, col, embed, hr, img, input, link, meta, source, track, wbr; each element still has distinct meaning and allowed contexts.

Conforming markup uses <br> without </br>; the HTML parser treats an erroneous </br> as another br start tag, but recovery does not make source conforming.

The slash in <br/> is ignored and does not close like XML. In <img src=http://example/x/>, an adjacent slash can become part of the unquoted attribute value.

The example gives DOMParser text containing </br> and observes two childless br elements.

Examples

<!doctype html>
<meta charset="utf-8">
<output id="result"></output>
<script>
const parsed = new DOMParser().parseFromString("<p id=sample>A<br>B</br>C</p>", "text/html");
const sample = parsed.querySelector("#sample");
result.textContent = `text=${sample.textContent}; breaks=${sample.querySelectorAll("br").length}; firstChildren=${sample.querySelector("br").childNodes.length}`;
</script>

Result

text=ABC; breaks=2; firstChildren=0

The result verifies HTML parser recovery; it neither describes XHTML syntax nor recommends the nonconforming end tag.

Sources