Nesting Elements Correctly
A free lesson from Swipe Coding · HTML, level 1 · updated October 2026
By the Swipe team, founded by Colin · how we make lessons
Elements can contain other elements, and this is called nesting. The rule is simple but important: whichever element you open last must be the one you close first — nested tags have to close in the reverse order they opened.
<p>This is <strong>very important</strong> text.</p>
Tags that cross each other instead of nesting properly are invalid and can cause a browser to render the page in unexpected ways, even if it technically still displays something.
<p>This is <strong>incorrectly nested</p></strong>
A good habit for avoiding nesting mistakes is indenting nested elements consistently as you write them, the way the examples in this track do. It costs nothing and makes crossed or missing tags far easier to spot at a glance, especially once a page has dozens of elements in it.
What is the correct rule for closing nested HTML tags?
Elements containing other elements is called ____.
<p>Some <strong>text</p></strong> is correctly nested HTML.
Keep your streak going in Swipe Coding
Swipe through every level of HTML on your iPhone — with XP, stars, streaks, a personal advisor and the full track beyond these free levels.
Get the Swipe apps →