HTML elements live inside other elements. Learn how parent-child relationships shape the DOM.
<ul> with a nested <ul> inside each <li>Common parent-child relationships:
<ul> contains <li> elements<div> contains paragraphs and headings<nav> contains links<html> is the root, <head> and <body> are its two main branches<html>
<body>
<section>
<h1>Jazz Playlist</h1>
<ul>
<li>Kind of Blue β Miles Davis</li>
<li>A Love Supreme β John Coltrane</li>
<li>Maiden Voyage β Herbie Hancock</li>
</ul>
</section>
</body>
</html>
That structure as a tree:
html
body
section
h1ul
li (Γ3)Key vocabulary:
<h1> and <ul> are siblings β both are children of <section>Open before you close β tags must nest properly; never close a parent before closing its children:
<!-- Wrong: p closes before strong -->
<p>The concert was <strong>incredible</p></strong>
<!-- Right: strong closes inside p -->
<p>The concert was <strong>incredible</strong>.</p>
Indent to show structure β browsers ignore whitespace, but humans depend on it:
<!-- Hard to read β no indentation -->
<article><h2>The Record Store</h2><p>Vinyl only.</p><ul><li>Jazz</li><li>Soul</li></ul></article>
<!-- Easy to read β proper indentation -->
<article>
<h2>The Record Store</h2>
<p>Vinyl only. No streaming.</p>
<ul>
<li>Jazz</li>
<li>Soul</li>
</ul>
</article>
Siblings example β three <a> elements, all children of <nav>:
<nav>
<a href="/">Home</a> <!-- child of nav, sibling of the other two -->
<a href="/work">Work</a> <!-- child of nav, sibling of the other two -->
<a href="/about">About</a> <!-- child of nav, sibling of the other two -->
</nav>