HTML void element (source code)

= HTML void element
{c}

An <HTML void element> is an <HTML element> whose HTML syntax permits no contents and no end tag. Examples include `br`, `img` and `input`. An ordinary element that happens to contain no text does not thereby become void.<HTML Standard by WHATWG>[§13.1.2, Elements, void elements and content restrictions]{ref}

For example, `<p>A<br>B</p>` contains a paragraph with text A, a line-break element and text B. The `br` start tag has no matching `</br>` end tag. An image's source and alternative text likewise use attributes such as `src` and `alt`, rather than child text between an image start/end pair.

The optional slash in `<br />` does not create the void behavior; `br` is void because of its element category. The same slash does not make `<div />` into a generally self-closing ordinary HTML element. Reading such source requires the <HTML> parser's rules.<HTML Standard by WHATWG>[§13.1.2.1, Start tags, optional slash on void elements]{ref}

Source conformance and general <Document Object Model> operations must also be distinguished. A program can construct a node tree that violates an element's HTML content restrictions. Such an object does not make nonconforming source or a void element's hypothetical children a valid way to serialize HTML. The <DOM element> model and the allowed source syntax answer different questions.