Semantic HTML means using elements that describe the meaning of your content, not just its appearance. Instead of wrapping everything in <div>, you use elements like <header>, <nav>, and <article> to communicate structure to browsers, screen readers, and search engines.
Why Semantics Matter
- Accessibility: Screen readers use semantic elements to navigate pages. A
<nav>is announced as navigation; a<div>is not. - SEO: Search engines understand your content hierarchy through semantic markup.
- Maintainability: Semantic code is self-documenting and easier to read.
Document Structure
Every HTML page should follow a clear structural hierarchy:
Ctrl+Enter
HTML
CSS
JS
Preview
Key rules:
- One
<main>per page — it wraps your primary content. <header>and<footer>can appear inside<article>or<section>, not just at the top level.- Use only one
<h1>per page, then<h2>through<h6>in order. Never skip heading levels.
Sectioning Elements
Use these elements to group related content:
Ctrl+Enter
HTML
CSS
JS
Preview
<section>groups thematically related content.<article>wraps self-contained content (blog posts, comments, cards).<aside>holds tangentially related content (sidebars, callouts).
Interactive Elements
HTML provides built-in interactive elements that work without JavaScript:
Ctrl+Enter
HTML
CSS
JS
Preview
Accessible Forms
Forms are where accessibility matters most. Every input needs a label, and grouping related fields helps users understand the structure:
Ctrl+Enter
HTML
CSS
JS
Preview
Key form rules:
- Always pair
<label>with inputs viaforandid, or wrap the input inside the label. - Use
<fieldset>and<legend>to group related fields. - Use the correct
typeattribute (email,tel,url,number) for built-in validation and mobile keyboards. - Prefer
<button type="submit">over<input type="submit">.
Text-Level Semantics
Choose elements based on meaning, not appearance:
| Element | Meaning | Not for |
|---|---|---|
<strong> | Important text | Just making text bold |
<em> | Stressed emphasis | Just making text italic |
<mark> | Highlighted/relevant text | Decorative highlighting |
<time> | Dates and times | Random numbers |
<code> | Inline code | Monospace styling |
<abbr> | Abbreviations | Tooltips on random text |
Ctrl+Enter
HTML
CSS
JS
Preview
Common Mistakes
- Using
<div>for everything — reach for semantic elements first. - Skipping heading levels — going from
<h1>to<h4>breaks the outline. - Missing
alton images — every<img>needsalt. Usealt=""for purely decorative images. - Using
<a>withouthref— an anchor withouthrefis not keyboard-focusable. Use<button>for actions.