
How you close a tag in HTML depends on the type of element. Some elements have an opening tag and a closing tag, while void elements have only a start tag. Knowing the difference helps you write clear, valid HTML.
1. Opening and closing tags in HTML5
When an element has content, the opening tag comes before that content and the closing tag comes after it. A closing tag starts with a forward slash after the opening angle bracket, followed by the element name.
<p>This is a paragraph of text.</p>
<a href="https://example.com">Link</a>
<div class="container">
Content inside the div.
</div>
In these examples, <p>, <a>, and <div> have closing tags </p>, </a>, and </div>. Keep your tags properly nested. Some HTML elements allow their end tags to be omitted in specific contexts, but writing them explicitly can make examples easier to read.
2. Void elements in HTML5
Void elements cannot contain child content and must not have a separate closing tag. Common examples include <img>, <br>, and <input>. In HTML, write the start tag with the closing angle bracket.
<img src="image.jpg" alt="Description">
<br>
<input type="text">
HTML also permits a trailing slash on void elements, a convention familiar from XHTML. In HTML, the slash does not change the meaning of the tag.
<img src="image.jpg" alt="Description" />
<br />
<input type="text" />
| Tag | Description |
|---|---|
<br> | Line break |
<hr> | Thematic break |
<img> | Image |
<input> | Input control |
<link> | Link to an external resource |
<meta> | Document metadata |
<col> | Table column |
<embed> | Embedded content |
<source> | Media source for an image, audio, or video element |
<wbr> | Optional line break |
You may also see <param> in older examples as a parameter for <object>. The element is obsolete in modern HTML.
In XHTML, empty elements use XML syntax such as <br />, <hr />, or <img src="…" alt="…" />. The spelling matters when the document is parsed as XML.
For the structure of an HTML document and more tag examples, see HTML: HyperText Markup Language.