Empty HTML Elements or Void Tags
In HTML, elements are usually written as a pair of tags, an opening tag and a closing tag, that together wrap content. However, some elements are designed to contain no content at all, so they appear only as a single opening tag. These are called empty elements, also known as void, singleton, or self-closing tags.
Syntax
The syntax for empty elements is almost identical to regular HTML tags, except they have no closing tag. A void HTML element can also include attributes within the tag itself, as shown below:
Empty Tag Syntax
<tag-name attribute='attribute-value' />
Basics of Empty HTML Elements
- Empty elements are written as a single tag and do not contain nested content.
- All information for the element is provided via attributes inside the tag, for example <img src="..." alt="...">.
- In HTML5 they are typically written without a trailing slash.
- Include any valid attributes you need, prioritizing semantic and accessible choices such as alt, title, and ARIA attributes.
- Only use the trailing slash when you must produce XHTML or XML-compatible markup.
Is a closing slash required for empty HTML5 elements?
Short answer: no. In HTML5, void elements are written without a trailing slash; a slash is only needed when you must produce XML or XHTML-compatible markup.
- In standard HTML5 use <br>, which is the simplest and most common form.
- If you need XML validity (XHTML), use the self-closing form <br /> so parsers accept it.
- People call these self-closing tags or singleton tags informally, but the correct term is HTML void elements.
Can we define our own singleton HTML elements?
Short answer: no. You cannot create custom HTML empty elements or void tags that behave as built-in singleton tags, because the Custom Elements spec requires different rules.
- The custom HTML element name must include a hyphen (-), for example <my-custom-element>.
- Custom HTML5 elements must have both an opening and a closing tag, for example <my-custom-element></my-custom-element>, so they are not valid as HTML singleton tags.
- Any attempt to use a self-closing custom element such as <custom-element /> is invalid markup in HTML, XHTML, and XML, so singleton tags must remain the built-in and spec-defined void elements.
Alphabetical List of Empty Tags
There are 24 empty elements in HTML, including some obsolete or deprecated tags also, and you can use the search to quickly filter the table.
Void Tag | Description |
---|---|
<!--...--> | Represents an HTML comment that browsers ignore during rendering but can hold notes or explanations in the code. |
<!DOCTYPE> | Specifies the HTML version and rendering mode for the browser, placed at the top of the document. |
<area> | Defines a clickable region in an image map to serve navigation or client-side links. |
<base> | Establishes the document's base URL used for resolving relative links and other resources. |
<basefont> | Previously set default font size, family, and color. |
<bgsound> | Played background audio in older nonstandard browsers. |
<br> | Inserts a line break inside text, commonly used within paragraphs and addresses for spacing. |
<col> | Specifies column properties inside a colgroup to control table column layout and presentation. |
<command> | Once defined a user-invokable command for menus and toolbars, support was scarce and removed. |
<embed> | Embeds external applications or interactive multimedia content such as plugins and widgets. |
<frame> | Defined a single section within a frameset to display an external document, replaced by modern layouts. |
<hr> | Draws a thematic break between sections to visually separate different content or topics. |
<img> | Embeds an image resource in the document, typically with source, alt, width, and height attributes. |
<input> | Creates a form control for user input, from text fields to checkboxes, radios, and buttons. |
<isindex> | Offered a single-line search prompt in early HTML, functionality replaced by explicit forms. |
<keygen> | Generated client-side key pairs for forms, later removed because of security and compatibility issues. |
<link> | Declares relationships to external resources, most often used to attach stylesheets or favicons. |
<meta> | Provides metadata about the page that browsers and search engines read and use for processing. |
<nextid> | Assigned a unique identifier seed for document elements in very early HTML drafts, long obsolete. |
<param> | Supplied name-value parameters for embedded objects, now largely superseded by modern APIs. |
<plaintext> | Caused all following content to render as raw text, an obsolete behavior not recommended today. |
<source> | Offers alternative media sources for audio, video, or picture elements to enable fallbacks. |
<track> | Attaches timed text tracks such as subtitles or captions to media elements like video and audio. |
<wbr> | Suggests a possible word break location to improve line wrapping for long words or URLs. |
HTML Void Tags That Never Use a Closing Slash
Some tags are inherently void and have never used a trailing slash, regardless of HTML or XHTML standards. These elements are always written without a slash and do not require a closing tag or slash.
- HTML <!-- comment --> Tag
- HTML <!DOCTYPE html> Tag
- HTML <nextid> Tag (obsolete)
- HTML <keygen> Tag (deprecated)
HTML Tags Reference
For a complete overview of all 140+ HTML tags, visit the HTML elements Reference.