Free HTML tutorial

HTML Elements: Tags, Nesting and Void Elements

Learn the difference between HTML tags and elements, how to nest elements correctly, and which common elements are void.

Tags and elements

An HTML element is made from tags and its content. Most elements have an opening tag and a closing tag around the content.

<p>This text is inside a paragraph element.</p>

Here, <p> is the opening tag, the text is the content, and </p> is the closing tag.

Nest elements in the right order

Elements can contain other elements. Close the inner element before closing its parent.

<p>Read the <strong>important</strong> instructions.</p>

Void elements

Void elements cannot contain child content and do not have closing tags. Common examples include <br>, <img>, <input> and <meta>.

Write explicit closing tags

Some elements have optional end tags under specific rules, but browsers may recover differently from malformed markup. Include the closing tags required for each element and nest them correctly.

Open the element demo (opens in a new tab)