A void element is an HTML element whose content model is nothing: it can never contain text or child elements, and therefore it is written with a start tag only and no end tag. Typical examples are img, br, input, meta and link. The HTML Living Standard defines a closed list of void elements, and the parser treats them specially so that a document stays well formed even though they are never explicitly closed.
Void elements are sometimes called empty elements, a synonym inherited from SGML and XML terminology. The distinction matters in practice because it governs how authors write markup, how the HTML parser builds the DOM, and how validators report errors such as a stray end tag or an unexpected self-closing slash.
How the HTML parser treats a void element
The HTML parser recognizes a void element by its tag name and closes it immediately after reading the start tag. When the tokenizer emits a start tag token for br or img, the tree builder inserts the element into the DOM and pops it off the stack of open elements at once, so no following text or tag can become its child.
This behavior is fixed by the parsing algorithm, not by author intent. Writing an end tag for a void element, for example a closing br tag, is a parse error; browsers recover in element-specific ways, and a stray closing br is even treated as a new line break for historical compatibility. Other stray void end tags are simply ignored.
Because the element can hold nothing, all of its information lives in attributes. An img element carries its resource in src and its text alternative in alt; an input element carries its behavior in type, name and value. The table below shows how this attribute-only design applies across common void elements.
| Element | Purpose | Key attributes |
|---|---|---|
| img | Embeds an image | src, alt, width, height, srcset |
| input | Form control | type, name, value, required |
| br | Line break inside text | None required |
| hr | Thematic break between paragraphs | None required |
| meta | Document metadata | charset, name, content |
| link | Relationship to an external resource | rel, href, as |
| source | Media or image candidate | src, srcset, type, media |
The complete list of void elements
The current HTML standard lists thirteen void elements: area, base, br, col, embed, hr, img, input, link, meta, source, track and wbr. This list is closed and cannot be extended by authors; a custom element or an unknown tag can never become void, because the parser decides voidness only from this fixed set.
Several older elements were void in earlier specifications and still receive void parsing for backward compatibility, including keygen, param, basefont, bgsound and frame. They are obsolete and nonconforming, so a validator rejects them, yet a browser still parses them without expecting an end tag. The groups below show where void elements appear in a typical document.
| Role | Void elements | Typical location |
|---|---|---|
| Document metadata | base, link, meta | Inside the head element |
| Embedded content | img, embed, source, track | Inside body, often within picture, video or audio |
| Text-level breaks | br, wbr, hr | Inside paragraphs or between blocks |
| Forms and tables | input, col | Inside form or colgroup |
| Image maps | area | Inside a map element |
Void elements compared with related concepts
A void element is not the same as an element that happens to be empty. A div or p with no content is still a normal element: it needs an end tag in most contexts and may receive children later through scripting. A void element is structurally incapable of having children, both in markup and in the DOM, where attempts to append text through the parser are impossible.
The distinction also separates HTML from XML-based syntax. In XHTML and other XML vocabularies, any element can be written in self-closing form, and the slash before the closing angle bracket is meaningful. In the HTML syntax, the trailing slash on a void element is permitted but ignored, and on a non-void element it has no effect at all, which leads to subtle bugs. The comparison below summarizes the differences.
| Concept | Can hold content | End tag | Trailing slash meaning |
|---|---|---|---|
| Void element in HTML | Never | Forbidden | Allowed and ignored |
| Empty normal element | Yes, currently none | Required in most cases | Ignored, element stays open |
| Self-closing element in XHTML | Depends on the vocabulary | Optional via self-closing form | Closes the element |
| Foreign element in SVG or MathML | Depends on the element | Optional via self-closing form | Closes the element |
| Template element content | Yes, in a separate fragment | Required | Ignored |
The SVG and MathML row matters because HTML documents may embed foreign content. Inside an inline SVG block, the parser honors the self-closing slash, so a circle or path element can be closed that way even though it is not on the void list.
Writing void elements correctly
Correct markup for a void element is simply the start tag with its attributes. Whether to add a trailing slash is a style decision, not a correctness one, and teams usually enforce one convention through a formatter or linter. Consistency matters more than the choice itself.
The decision table below covers the situations that most often raise the question of how to write a void element.
| Situation | Recommended form | Reason |
|---|---|---|
| Plain HTML document | Start tag without slash | Shortest form, matches the standard examples |
| Markup that must also parse as XML | Self-closing form with slash | XML parsers require explicit closing |
| JSX in React projects | Self-closing form with slash | JSX syntax requires every element to be closed |
| Templates processed by a formatter | Whatever the formatter emits | Avoids noisy diffs and review churn |
| Email HTML for legacy clients | Either form, tested in target clients | Rendering engines vary widely |
- Always provide meaningful alt text on
img, because the element has no content that could serve as a fallback. - Use
bronly for line breaks that belong to the content, such as addresses or poems, never for vertical spacing. - Give every
inputan associated label element, since the void input cannot contain its own visible label.
Common mistakes and how validators report them
Most problems with void elements come from treating them like containers or from copying XML habits into HTML. Validators flag several of these cases, while others silently change the DOM in ways that only appear as layout or accessibility defects.
| Mistake | What actually happens | Fix |
|---|---|---|
| End tag on a void element | Parse error; browser ignores or reinterprets it | Remove the end tag |
| Text placed inside img or input | Text becomes a sibling node after the element | Move text to alt, a label or a caption |
| Self-closing slash on div or span | Element stays open and swallows following content | Write an explicit end tag |
| Obsolete void element such as param | Parsed, but reported as nonconforming | Replace with a current element or attribute |
| Missing alt on img | Screen readers may announce the file name | Add descriptive or empty alt text |
The third row is the most dangerous misconception. Authors who believe a slash closes any element may write a self-closing div, and the parser then nests every subsequent element inside it, which can break CSS selectors, flex layouts and scripts that depend on DOM structure.
In plain words
Most HTML elements work like boxes: they open, hold some text or other elements, and then close. A void element is a box that can never hold anything. An image, a line break or a form field is complete on its own, so it has only an opening tag and carries all its details in attributes.
Think of a sticker on a page compared with an envelope. An envelope can contain a letter, so it needs to be opened and sealed. A sticker is just placed and finished. Void elements are the stickers of HTML, and browsers know the short list of them by heart.
A real-world example
A front-end developer migrates a marketing site from an old XHTML template to a modern HTML document. The template contains hundreds of self-closing tags, and a teammate has also written several empty div placeholders in self-closing form, believing the slash closes them.
After the migration, the footer suddenly appears inside a sidebar column. The HTML validator reports no error for the void elements, because a slash on img, meta and br is allowed, but the DOM inspector shows that each self-closing div stayed open and swallowed the rest of the page. The developer replaces those placeholders with explicit end tags and configures the formatter to write void elements without slashes across the project.
The result is a clean validator report and a stable layout, and the team adds a lint rule that rejects self-closing syntax on non-void elements in future pull requests.