Skip to main content
Albero Academy

Elements & Tags

How tags, elements and nesting work.

Foundations8 min

HTML is built from elements. An element is usually an opening tag, some content, and a closing tag — the tags tell the browser what kind of content it is.

Anatomy of an element

opening tag, content, closing tag
<p>This is a paragraph.</p>
│ content │
└ opening tag └ closing tag (note the /)
<img src="cat.jpg" alt="A cat" /> <!-- void element: no closing tag -->

Nesting

Elements nest inside one another, forming a tree. Nested elements must be closed in the reverse order they were opened:

correct nesting
<p>This is <strong>bold and <em>italic</em></strong> text.</p>
<!-- WRONG — tags overlap instead of nesting -->
<p><strong>bad <em>overlap</strong></em></p>

Key takeaways

  1. 01An element = opening tag + content + closing tag (e.g. <p>...</p>).
  2. 02Void elements (<img>, <br>, <input>) have no content or closing tag.
  3. 03Elements nest to form a tree; close inner elements before outer ones.
  4. 04Overlapping tags are invalid — proper nesting is required.

Finished this chapter?

Mark it complete to track your progress through HTML.