You’ve learned the basic structure elements. Now it’s time to think deeply about what each piece of content means and choose elements that accurately represent that meaning. This is semantic HTML mastery.
What you’ll learn:
All semantic HTML elements and when to use them
Text-level semantics (emphasis, importance, definitions, code)
Content-level semantics (article, section, nav, aside)
How semantic HTML improves accessibility and SEO
Real-world patterns and best practices
When NOT to use semantic elements
Prerequisites:
Semantic HTML is about precision in meaning. Consider this example:
<!-- Without semantics -->
< div > Today is my birthday! </ div >
< p > Today is my birthday! </ p >
The second version tells search engines and screen readers: “This is a paragraph of text.” The machine understands not just what to display, but what it is .
This matters because:
Search engines can extract and rank your important content
Screen readers can navigate and announce content appropriately
Your code documents intent for future developers
Machines can extract structured data automatically
These elements describe the meaning of text within sentences and paragraphs.
For text with strong importance or urgency:
Interactive code playground requires JavaScript. Here's the code:
<p>
This product is <strong>not</strong> suitable for children under 3.
</p>
<p>
The <strong>deadline is midnight tonight</strong>. Don't miss it!
</p>
Screen readers pronounce <strong> with emphasis. Use it for warnings, critical information, or emphasized words that change meaning.
For text you would stress if speaking aloud:
Interactive code playground requires JavaScript. Here's the code:
<p>
I <em>really</em> think you should see this movie.
</p>
<p>
She said she was <em>not</em> attending the meeting.
</p>
The difference between “I really think” (with emphasis) and “I really think” (without) changes the meaning.
For text that’s highlighted for reference:
Interactive code playground requires JavaScript. Here's the code:
<p>
Please note the <mark>important deadline</mark> in your calendar.
</p>
<p>
In your search results: "The <mark>quick</mark> brown fox
jumped over the fence."
</p>
Use <mark> for search highlights, important passages, or key information.
Show content that’s been removed or added:
Interactive code playground requires JavaScript. Here's the code:
<p>
Price: <del>$50</del> <ins>$35</ins>
</p>
<p>
The meeting is <del>Friday at 2pm</del> <ins>Wednesday at 3pm</ins>.
</p>
Perfect for showing edits, corrections, or price changes.
For inline code snippets:
Interactive code playground requires JavaScript. Here's the code:
<p>
Use the <code>document.getElementById()</code> function to select elements.
</p>
<p>
The <code>background-color</code> CSS property sets the background color.
</p>
For keyboard commands or key combinations:
Interactive code playground requires JavaScript. Here's the code:
<p>
Press <kbd>Ctrl</kbd> + <kbd>S</kbd> to save your work.
</p>
<p>
To open the developer tools, press <kbd>F12</kbd>.
</p>
For computer output or results:
Interactive code playground requires JavaScript. Here's the code:
<p>
When you run the code, you'll see: <samp>Hello, World!</samp>
</p>
For mathematical or programming variables:
Interactive code playground requires JavaScript. Here's the code:
<p>
The formula is <var>a</var> = <var>b</var> + <var>c</var>
</p>
<p>
If <var>x</var> is greater than 10, execute this code.
</p>
Provide the full form of abbreviations:
Interactive code playground requires JavaScript. Here's the code:
<p>
The <abbr title="Hypertext Markup Language">HTML</abbr> specification
is maintained by the <abbr title="World Wide Web Consortium">W3C</abbr>.
</p>
Hover over the abbreviations to see the expanded form.
For titles of creative works being cited:
Interactive code playground requires JavaScript. Here's the code:
<p>
My favorite book is <cite>To Kill a Mockingbird</cite> by Harper Lee.
</p>
<p>
The song <cite>Imagine</cite> was released by John Lennon.
</p>
Use <cite> for book titles, movie names, song titles, and artwork names.
When defining a term for the first time:
Interactive code playground requires JavaScript. Here's the code:
<p>
<dfn>Semantics</dfn> refers to the meaning of words and how they relate to each other.
</p>
<p>
A <dfn>viewport</dfn> is the visible area of a web page in a browser window.
</p>
Use <dfn> the first time you define an important term.
For dates and times that machines can parse:
Interactive code playground requires JavaScript. Here's the code:
<p>
The event is on <time datetime="2024-12-25">Christmas Day</time>.
</p>
<p>
I wake up at <time>6:30 AM</time> every morning.
</p>
<p>
The post was published <time datetime="2024-12-10T14:30">about 2 hours ago</time>.
</p>
The datetime attribute uses the ISO 8601 format, which search engines and assistive technology can parse.
For side comments, fine print, or disclaimers:
Interactive code playground requires JavaScript. Here's the code:
<p>
This offer is valid <small>while supplies last</small>.
</p>
<p>
Subscribe today <small>$9.99/month, cancel anytime</small>.
</p>
Let’s review and expand on the major content elements:
<article> : Independently distributable content
<section> : A thematic grouping of content
<!-- A blog with multiple posts -->
<!-- A single article with sections -->
< h2 > Understanding Web Development </ h2 >
For contact information related to an article or page:
Interactive code playground requires JavaScript. Here's the code:
<article>
<h2>Contact the Author</h2>
<address>
Written by <a href="mailto:author@example.com">Jane Doe</a>.<br>
Visit their website at <a href="https://example.com">example.com</a>.
</address>
</article>
Use <address> in footers, author info, or contact sections.
For longer quotes:
Interactive code playground requires JavaScript. Here's the code:
<blockquote cite="https://www.w3.org/WAI/">
<p>
Web accessibility means that people with disabilities can use the Web equally.
It encompasses all disabilities that affect access to the Web.
</p>
<footer>— <cite>W3C Web Accessibility Initiative</cite></footer>
</blockquote>
Always include a cite attribute with the source URL.
For images with captions that are referenced:
Interactive code playground requires JavaScript. Here's the code:
<figure>
<img src="https://images.unsplash.com/photo-1453728691169-d74f74d3c161"
alt="A laptop with code on screen"
width="300"
height="200">
<figcaption>
Figure 1: A typical web development workspace with code editor and browser.
</figcaption>
</figure>
Use <figure> when the image is referenced in text (like “Figure 1 shows…”).
Create expandable sections:
Interactive code playground requires JavaScript. Here's the code:
<details>
<summary>What is HTML?</summary>
<p>HTML is HyperText Markup Language. It defines the structure and content of web pages.</p>
</details>
<details>
<summary>What is CSS?</summary>
<p>CSS is Cascading Style Sheets. It controls the appearance and layout of web pages.</p>
</details>
The <summary> is clickable to expand/collapse the <details> content. Great for FAQs!
Here’s a complete article using many semantic elements:
Interactive code playground requires JavaScript. Here's the code:
<article>
<header>
<h1>Understanding Web Accessibility</h1>
<p>Published <time datetime="2024-12-10">December 10, 2024</time></p>
<p>By <address><a href="mailto:author@example.com">Sarah Johnson</a></address></p>
</header>
<p>
<dfn>Web accessibility</dfn> means <mark>all people can use your website</mark>,
including people with disabilities.
</p>
<section>
<h2>Why It Matters</h2>
<blockquote cite="https://w3.org">
<p>The Web is fundamentally designed to work for all people, whatever their hardware, software, language, location, or ability.</p>
<footer>— W3C Web Accessibility Initiative</footer>
</blockquote>
</section>
<section>
<h2>Key Principles</h2>
<details>
<summary><strong>Perceivable</strong> — Users can see or hear content</summary>
<p>Content must be presentable to users in ways they can perceive.</p>
</details>
<details>
<summary><strong>Operable</strong> — Users can navigate and use controls</summary>
<p>Components must be operable via keyboard.</p>
</details>
</section>
<section>
<h2>Quick Tips</h2>
<ul>
<li>Always use <code>alt</code> text on images</li>
<li>Use semantic HTML elements correctly</li>
<li>Test with screen readers like <kbd>NVDA</kbd></li>
</ul>
</section>
</article>
Not everything should be semantic. Sometimes <div> or <span> are correct:
<!-- Good: <div> for layout grouping without semantic meaning -->
< div class = " sidebar-widget " >
<!-- Good: <span> for styling without semantic meaning -->
< p > This is < span class = " highlight " > important </ span > information. </ p >
<!-- Bad: Forcing semantic meaning where there is none -->
< article class = " decorative-banner " > Huge Sale! </ article >
<!-- Use <div> instead of <article> -->
<!-- Bad: <em> just for italics with no emphasis -->
< p > The < em > Mona Lisa </ em > is a painting. </ p >
Choose the most specific element for your content
Nest elements properly — don’t break the hierarchy
One <main> per page — for unique content
Use <h1> once per page — for the main title
Always use <nav> correctly — for site navigation, not just links
Provide context — use cite, datetime, and title attributes
Think about meaning first — then styling with CSS
Create a well-structured article using semantic elements:
Interactive code playground requires JavaScript. Here's the code:
<article>
<header>
<h1>Your Article Title</h1>
<p>Published <time datetime="2024-12-10">Today</time></p>
</header>
<p>Introduction paragraph with a <mark>highlighted key point</mark>.</p>
<section>
<h2>Main Topic</h2>
<p>Content about your main topic.</p>
<p>You can mention <code>important-code</code> inline.</p>
</section>
<section>
<h2>More Information</h2>
<details>
<summary>Click for more details</summary>
<p>Additional information appears here.</p>
</details>
</section>
</article>
Semantic HTML gives precise meaning to content
Text elements: <strong>, <em>, <mark>, <code>, <kbd>, <abbr>, <time>, etc.
Content elements: <article>, <section>, <nav>, <aside>, <header>, <footer>
Specialized elements: <figure>, <blockquote>, <details>, <address>
Use semantics for meaning, not styling
Semantic HTML improves SEO, accessibility, and maintainability
Forms
Build interactive forms with proper input types and validation.
Continue →
Tables
Create accessible data tables with proper structure.
Continue →