Semantic HTML is about using the right tag for the job. It improves accessibility, SEO, and maintainability.
Compare these two approaches:
<div class="header">
<div class="nav">
<div class="nav-item">Home</div>
</div>
</div>
<div class="main">
<div class="article">
<div class="title">My Article</div>
<div class="content">...</div>
</div>
</div>
<header>
<nav>
<a href="/">Home</a>
</nav>
</header>
<main>
<article>
<h1>My Article</h1>
<p>...</p>
</article>
</main>
<header> <!-- Top of page or section -->
<nav> <!-- Navigation links -->
<ul>
<li><a href="/">Home</a></li>
</ul>
</nav>
</header>
<main> <!-- Primary content -->
<article> <!-- Self-contained content -->
<section> <!-- Thematic grouping -->
<h2>Section Title</h2>
</section>
</article>
<aside> <!-- Tangentially related content -->
<h3>Related Links</h3>
</aside>
</main>
<footer> <!-- Footer information -->
<p>© 2025</p>
</footer>
<h1> to <h6> <!-- Headings (hierarchical) -->
<p> <!-- Paragraphs -->
<blockquote> <!-- Quoted content -->
<figure> <!-- Self-contained content -->
<img src="chart.png" alt="Sales chart">
<figcaption>Q4 Sales Data</figcaption>
</figure>
<pre> <!-- Preformatted text -->
<code> <!-- Code snippets -->
<strong> <!-- Important (bold) -->
<em> <!-- Emphasis (italic) -->
<mark> <!-- Highlighted text -->
<time> <!-- Time/date -->
<time datetime="2025-11-03">November 3, 2025</time>
<abbr> <!-- Abbreviation -->
<abbr title="HyperText Markup Language">HTML</abbr>
Screen readers use semantic HTML to navigate:
<!-- Screen reader can announce: "navigation, 5 links" -->
<nav>
<a href="/">Home</a>
<a href="/about">About</a>
<a href="/blog">Blog</a>
<a href="/contact">Contact</a>
<a href="/faq">FAQ</a>
</nav>
Users can jump between landmarks:
Search engines understand structure:
<article>
<h1>Main Topic</h1> <!-- Most important -->
<h2>Subtopic 1</h2> <!-- Secondary -->
<h3>Detail A</h3> <!-- Tertiary -->
<h3>Detail B</h3>
<h2>Subtopic 2</h2>
</article>
Semantic HTML is self-documenting:
<!-- Clear purpose without classes -->
<header>
<nav aria-label="Primary navigation">
...
</nav>
</header>
Semantic forms are crucial for accessibility:
<form>
<fieldset>
<legend>Personal Information</legend>
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<label for="country">Country:</label>
<select id="country" name="country">
<option value="">Select...</option>
<option value="us">United States</option>
<option value="uk">United Kingdom</option>
</select>
</fieldset>
<button type="submit">Submit</button>
</form>
Use the right list type:
<ul> <!-- No particular order -->
<li>Apples</li>
<li>Bananas</li>
<li>Oranges</li>
</ul>
<ol> <!-- Specific order matters -->
<li>Preheat oven</li>
<li>Mix ingredients</li>
<li>Bake for 30 minutes</li>
</ol>
<dl> <!-- Term/definition pairs -->
<dt>HTML</dt>
<dd>HyperText Markup Language</dd>
<dt>CSS</dt>
<dd>Cascading Style Sheets</dd>
</dl>
Use ARIA attributes to enhance semantics:
<!-- Current page indicator -->
<nav>
<a href="/" aria-current="page">Home</a>
<a href="/about">About</a>
</nav>
<!-- Expandable content -->
<button aria-expanded="false" aria-controls="details">
Show Details
</button>
<div id="details" hidden>
Additional information...
</div>
<!-- Loading state -->
<button aria-busy="true">
Loading...
</button>
<h1>Title</h1>
<h3>Subtitle</h3> <!-- Should be h2 -->
<div class="button">Click me</div> <!-- Use <button> -->
<div onclick="...">Link</div> <!-- Use <a> -->
<a href="...">Click here</a> <!-- Bad -->
<a href="...">Read our privacy policy</a> <!-- Good -->
<img src="chart.png"> <!-- Bad -->
<img src="chart.png" alt="2024 sales showing 20% growth"> <!-- Good -->
Use these tools:
Semantic HTML enables keyboard navigation:
Tab - Move between interactive elementsEnter - Activate buttons/linksSpace - Toggle checkboxes, activate buttonsStructure content logically:
<body>
<header>
<h1>Site Name</h1>
</header>
<main>
<article>
<h1>Article Title</h1> <!-- h1 in article context -->
<section>
<h2>Section</h2>
</section>
</article>
</main>
</body>
Semantic HTML is:
Start using semantic HTML today. Your users, search engines, and future self will thank you.
Write semantic HTML. Make the web better. 🌐