HTML basics: semantic structure and the document tree
HTML isn't just text on a page — it's a tree of meaning. Good tags describe what each part is (a heading, a list, a link), which helps browsers, search engines, and screen readers alike.
The big idea
HTML tags nest into a tree that structures a document semantically — using tags that describe meaning, not just appearance.
See it in code
Two tags, two jobs. <h1> is the top-level heading; <p> is a paragraph of body text. Almost every page starts about here:
<h1>Learn to Code</h1>
<p>A quick guide to getting started.</p>That's already valid HTML. The browser renders the tags in order, giving the heading weight and the paragraph plain body text.
Content that has an order wants a list. <ol> is an ordered (numbered) list, and each <li> is one step inside it:
<h1>Learn to Code</h1>
<p>A quick guide to getting started.</p>
<ol>
<li>Pick a language</li>
<li>Build a small project</li>
<li>Share it</li>
</ol><ol> numbers the items for you, and says something a paragraph can't: these steps happen in sequence. That meaning is the whole point of semantic tags.
Now wrap it in semantic tags. <article> holds the whole piece, <section> groups the steps, and a <footer> with an <a> adds a link region. The indentation mirrors the tree — children nested inside parents:
<article>
<h1>Learn to Code</h1>
<p>A quick guide to getting started.</p>
<section>
<h2>Steps</h2>
<ol>
<li>Pick a language</li>
<li>Build a small project</li>
<li>Share it</li>
</ol>
</section>
<footer>
<a href="https://example.com">More resources</a>
</footer>
</article>Semantic tags carry meaning a plain <div> can't. <ol> says 'these steps are ordered', <nav>/<footer> mark page regions, <a href> creates a link. That meaning is what a screen reader announces and a search engine indexes — structure is accessibility.
Nesting elements into a tree is how every document format works: XML, JSON, even a file system's folders. The 'semantic vs presentational' distinction — describe what something is, style it separately — is a principle that keeps large codebases maintainable.
Try it yourself
Add a <nav> with two links before the article. Then nest a <ul> (unordered list) inside a list item to make a sub-list, and watch the tree deepen.
The common mistake
Using <div> for everything ('div soup'). A <div> is meaningless — it says nothing about content. Reaching for semantic tags (<section>, <article>, <nav>, <button>) makes your page accessible and far easier to style and maintain.
What it unlocks
Structure is the base for styling with CSS, reading and changing the page via the DOM, and building reusable components.