What may go inside what
HTML elements follow nesting rules that decide which tags may sit inside which. Breaking these rules can make the browser auto-close tags or move elements around.
Step by step
- Inside
<p>, use only phrasing (inline) tags like<strong>or<a>, never blocks like<div>or<ul>. - Inside
<ul>and<ol>, put only<li>items directly (nested lists go inside an<li>). - Inside
<button>, use only phrasing tags like<span>, and never put a link<a>or another button inside. - Inside
<a>, never nest another<a>or a<button>. - Inside
<table>, put<caption>,<thead>,<tbody>,<tfoot>, or<tr>— never bare<p>or<td>.
The card, bug marked
1<nav aria-label="Menu">
2 <ul>
3 <li><a href="/">Home</a></li>
4 <a href="bio.html">Bio</a>
5 <li><a href="faq.html">FAQ</a></li>
6 </ul>
7</nav>
This is how it's right
<p>Bring these items:</p>
<ul>
<li><a href="gear.html">Gear</a></li>
<li>A tuner</li>
</ul>
<button type="button">
<span class="label">Book</span>
</button>
Exercises for this topic
Key rule
Match each parent tag's allowed children, and never nest interactive elements inside each other.
Where you'll meet this
Nesting mistakes show up often in cards, menus and tables when you wrap whole blocks in <p>, <a> or <button>. Checking what a tag may contain avoids surprising layout bugs.