Void elements are specific HTML tags that cannot contain any "children," such as text or nested tags. These elements are defined by having a start tag only; you must never use a closing tag with them. In the context of SEO, void elements include critical metadata and resource tags like meta, link, and img.
What are Void Elements?
In the HTML technical specification, void elements are one of six distinct element types. While normal elements (like <p> or <div>) act as containers for content, void elements are self-contained. The browser's HTML parser is programmed to know that these specific tags end as soon as the start tag is closed with a >.
The HTML, SVG, and MathML specifications define exactly what each element can contain. Because void elements have no end tag, they have no space to hold content. Any text or tags placed "inside" a void element in your code will be treated by the browser as following the element rather than being part of it.
Why Void Elements matter
Understanding these elements helps you maintain clean, valid code which ensures browsers and search engines interpret your page correctly.
- Prevent parsing errors. Using a closing tag on a void element (e.g.,
<input></input>) is invalid HTML and can cause the browser to misinterpret your site structure. - Standardize SEO metadata. Core SEO components like
<meta>and<link>are void elements; incorrect syntax can lead to issues with how search engines read your descriptions or canonical tags. - Ensure crawlability. Technical errors in HTML structure can theoretically impact how a bot renders a page, though modern parsers are often forgiving of minor mistakes.
- Maintain XHTML compatibility. Many developers use a trailing slash (
<img />) to keep code compatible with XML or XHTML systems, even though HTML4 and HTML5 parsers ignore the slash.
How Void Elements work
Void elements consist of a start tag followed by a closing bracket. Unlike standard elements, they do not wrap around content.
- Format: A less-than sign (
<), the tag name, any attributes, and a greater-than sign (>). - No End Tags: The presence of an end tag (like
</img>) is a syntax error. - Parsing Logic: When a browser encounters a void element, it immediately starts processing what comes after it as a sibling rather than a child.
- JavaScript Interactions: While you can technically use JavaScript to add child nodes to these elements in the DOM (Document Object Model), this is considered bad practice and produces unreliable results.
Types of Void Elements
The HTML specification defines a specific list of void elements. If a tag is not on this list, it is not a void element and typically requires a closing tag.
| Element | Purpose |
|---|---|
<area> |
Defines an area inside an image map. |
<base> |
Specifies the base URL for all relative URLs in a document. |
<br> |
Produces a line break in text. |
<col> |
Defines column properties for a table. |
<embed> |
A container for an external resource or interactive content. |
<hr> |
Represents a thematic break or horizontal rule. |
<img> |
Embeds an image. |
<input> |
Creates interactive controls for web based forms. |
<link> |
Specifies relationships between the current document and external resources. |
<meta> |
Represents various types of metadata. |
<source> |
Specifies multiple media resources for media elements. |
<track> |
Defines timed text tracks for media. |
<wbr> |
Represents a "Word Break Opportunity." |
Note: The <param> element is also a void element but is currently deprecated.
Best practices
Skip the end tag. Never write a closing tag for these elements. For example, use <br> instead of <br></br>.
Use quotes for attribute values. Always wrap your attribute values in double or single quotes. This prevents the parser from accidentally including characters like slashes in your URLs or values.
Be careful with trailing slashes. In standard HTML, a slash at the end of a void element (like <hr />) is ignored by the parser. Use it only if your workflow requires XHTML compatibility or if your code formatter adds it automatically.
Separate slashes from unquoted attributes. If you must use a trailing slash and your attributes are unquoted, ensure there is a space before the slash.
Common mistakes
Mistake: Using a closing tag on a void element.
Fix: Remove the closing tag. Use <meta name="description" content="..."> instead of <meta ...></meta>.
Mistake: Adding a trailing slash to a non-void element to try and "close" it.
Fix: Non-void elements like <script> or <div> must have an explicit closing tag. Writing <script src="..."/> will not close the script; the browser will treat the rest of your page as part of the script.
Mistake: Placing a slash directly after an unquoted attribute.
Fix: Add a space or use quotes. For example, <img src=logo.png/> makes the browser think the file name is logo.png/, which results in a broken image. Use <img src="logo.png" /> or <img src=logo.png />.
Mistake: Attempting to nest text inside a void element.
Fix: Move the text outside the tag. A <br>Click here</br> will not work as intended; the text will simply appear after the break in the browser's render.
FAQ
Are self-closing tags required in HTML?
No. In standard HTML, self-closing tags (like <br />) do not exist. HTML parsers simply ignore the trailing slash character. However, they are required in XML, XHTML, and SVG. Some code formatters add them to HTML for better readability or compatibility with other systems.
Can I put text inside an <img> tag for SEO?
No. You cannot place content between the tags of a void element because there is no closing tag. For SEO image descriptions, use the alt attribute within the start tag: <img alt="description of image">.
Is it wrong to use the trailing slash (<img />)?
It is not "wrong" in a functional sense because modern HTML parsers ignore it. However, it is unnecessary. If you do use it, follow the rule of ensuring there is a space before the slash if your attributes are unquoted to avoid breaking your URLs.
What happens if I try to use JavaScript to add a child to a void element?
While the DOM might allow you to programmatically attach a child node, the result is unreliable across different browsers and is explicitly noted as bad practice in technical documentation.
How do foreign elements like SVG handle this?
In SVG and MathML, elements that cannot have child nodes are allowed to be marked as self-closing. In these specific namespaces, if a tag is marked as self-closing, it must not have an end tag.