In the last lesson you met the page skeleton. Now we zoom right in on the building block it is made of: the element. Once you can read an element the way you read a word, the rest of HTML is just vocabulary.
1The anatomy of an element
Most HTML elements are written as a pair of tags wrapped around some content:
- The opening tag —
<p>— marks where the element starts. - The content — the text or other elements inside.
- The closing tag —
</p>— marks where it ends. Note the forward slash; that slash is the only difference, and forgetting it is the single most common beginner mistake.
/ in front.- An element is usually an opening tag + content + closing tag.
- The closing tag repeats the name with a slash:
<p>…</p>. - Forgetting the closing slash is the most common beginner error.
2Void elements — tags that stand alone
A few elements have no content, so they have no closing tag. These are called void (or empty) elements. They do their job in a single tag:
<br>— a line break.<hr>— a horizontal divider line.<img>— an image (you give it a source instead of content).<input>— a form field.
<br />. In modern HTML that slash is optional and does nothing — <br> is perfectly correct.- Void elements like
<br>,<hr>,<img>and<input>have no content and no closing tag. - The trailing slash in
<br />is optional in modern HTML.
3Nesting — elements inside elements
Elements live inside other elements, forming a tree of parents and children. The golden rule: tags must close in the reverse order they opened, like closing a set of brackets.
Correct — the inner element closes first:
<p>This is <strong>very</strong> important.</p>
Wrong — the tags overlap and cross over:
<p>This is <strong>very</p></strong>
Try it yourself below. The editor keeps a <strong> word inside a paragraph — add an <em> (italic) word too, making sure every tag you open, you close.
- Elements nest to form a tree of parents and children.
- Tags must close in reverse order — the inner tag closes before the outer one.
- Overlapping tags like
<strong>…</p></strong>are invalid.
★ Practical: a tiny nested page
In the playground above, build three lines:
- A paragraph with one
<strong>(bold) word. - A paragraph with one
<em>(italic) word. - A single
<hr>between them — and notice it needs no closing tag. - Confirm every opening tag has a matching closing tag (except the void
<hr>).
Ready to test yourself?
Take the short quiz. Score 60% or more to mark this lesson complete.
Start the quiz →💡 Log in to save your progress and earn the certificate.