Sub topic 1
What 'semantic' means in HTML
Prerequisites
This chapter assumes you can read and write basic HTML: tags, attributes and nesting. You should know how to open your browser's developer tools and inspect an element. A basic idea of what CSS does helps, but it is not required.
Meaning versus appearance
An HTML element does two separate things. It carries a meaning, and it comes with a default appearance. Semantic HTML means choosing elements for their meaning first.
Consider <h1>. Its meaning is "the top-level heading of this content". Its default appearance is large, bold text. These two things are independent. CSS can make an <h1> small and light, and the element is still a top-level heading. CSS can also make a <div> large and bold, but the <div> is still not a heading.
Browsers and other software read the meaning from the element name. They do not infer it from the look. That is the core idea of this chapter:
- Elements describe what content is.
- CSS controls how content looks.
- Choose the element by asking "what is this?", never "how do I want it to look?".
Who reads the meaning
Several kinds of software depend on your element choices.
| Consumer | What it does with semantics |
|---|---|
| Browser | Provides built-in behavior, such as focus, keyboard activation, form submission and find-in-page. |
| Assistive technology | Announces roles and names, and offers shortcuts such as "jump to the next heading" or "jump to main content". |
| Search engines | Use headings, lists, tables and dates to understand what a page is about. |
| Reader modes and extractors | Find the main article and strip navigation and footers. |
| Other developers | Read the markup to learn the structure without opening the CSS. |
Many of these benefits are free. You do not write extra code to get them. You get them by using the right element.
A first comparison
Here is a page fragment built only from generic elements. It looks fine once styled, but it tells software almost nothing.
<div class="top">
<div class="title">Latest articles</div>
<div class="links">
<div class="link">Articles</div>
<div class="link">About</div>
</div>
</div>
<div class="content">
<div class="big">Pick an article to start reading.</div>
</div>Here is the same content with elements that say what each part is.
<header>
<a href="/">Example Site</a>
<nav aria-label="Primary">
<ul>
<li><a href="/articles">Articles</a></li>
<li><a href="/about">About</a></li>
</ul>
</nav>
</header>
<main>
<h1>Latest articles</h1>
<p>Pick an article to start reading.</p>
</main>The second version gives a screen reader user a navigation region and a main region to jump to. It also gives them a real list of links and a real top-level heading. The links work with the keyboard. In the first version, nothing is focusable, nothing is a link, and nothing is a heading.
What you get for free
The clearest way to see the value of semantics is to compare a native control with an imitation.
<!-- Avoid: no role, no keyboard support, not focusable -->
<div class="btn" onclick="save()">Save</div>
<!-- Prefer: focusable, keyboard operable, announced as a button -->
<button type="button" onclick="save()">Save</button>The <button> gives you four things without extra code:
- It is in the keyboard tab order.
- It activates on both Enter and Space.
- It is exposed with the role "button", so a screen reader announces it as one.
- It can be disabled, and it takes part in forms.
To make the <div> match, you would add tabindex="0", role="button", key handlers for Enter and Space, and disabled-state handling. Even then you would likely miss an edge case. The native element is shorter and more reliable.
The same applies to <details> and <summary>, which provide a working disclosure widget with no JavaScript:
<details>
<summary>Shipping information</summary>
<p>Orders ship within two business days.</p>
</details>Clicking the summary, or pressing Enter or Space on it, toggles the content. The state is exposed to assistive technology automatically.
Semantics at three levels
Semantic elements work at different scales. The rest of this tutorial covers each level in its own chapter. This list gives the map.
- Page level:
header,nav,main,asideandfootermark the regions of a page. - Content level: headings,
section,article, lists,figureandblockquoteorganize and group content. - Phrase level:
strong,em,code,abbrandtimemark meaning inside a sentence.
Some elements go beyond these levels. Tables, form controls and interactive elements carry meaning through relationships, such as a header cell tied to its data cells, or a label tied to its input.
Semantic does not mean visual
A common confusion is to treat elements as styling tools. Two examples show why this causes problems.
<strong> and <b> often look the same. They are not the same. <strong> means "this text is important". <b> means "draw attention to this text without saying it is more important", for example a keyword in a summary. <em> means stress emphasis, the kind that changes the meaning of a sentence. Compare "I did not say he stole it" with "I did not say he stole it". A screen reader can change its voice for <em> and <strong>.
<article>
<h2>Why semantics matter</h2>
<p>Published <time datetime="2026-11-30">30 November 2026</time> by Sam Lee.</p>
<p>Use <strong>meaningful</strong> elements, not just ones that <em>look</em> right.</p>
</article>In the same way, a heading is not "big text". If you need big text that is not a heading, use a <p> with a CSS class. If you need a heading that looks small, use the right heading level and style it with CSS.
Where non-semantic elements fit
<div> and <span> have no meaning. They are generic containers, and they are the right choice when no semantic element fits. Typical uses are grouping elements for layout or giving CSS and JavaScript a hook. A later chapter covers this in detail. For now, remember that "semantic HTML" does not mean "never use <div>". It means "do not use <div> where a more meaningful element exists".
Seeing semantics in devtools
You can check what the browser makes of your markup. Open your browser's developer tools and find the Accessibility panel. In Chrome and Edge, it sits next to the Elements panel. In Firefox, it is a separate tab.
- Inspect a
<button>and a styled<div>side by side. - Read the Role field. The button shows "button". The div shows "generic" or "none".
- Read the Name field. The button's name comes from its text content.
- Check whether the element is focusable.
This view is the accessibility tree: the browser's version of the page that assistive technology reads. A later chapter explains it in detail. The point here is that your element choices decide what appears in it.
Common misunderstandings
- "Semantic HTML is only about accessibility." Accessibility is the largest benefit, but keyboard behavior, reader modes, search and maintainability all benefit as well.
- "More semantic elements is always better." An element must be correct, not merely present. A wrong
<section>or a<table>used for layout adds noise. - "Semantic HTML replaces ARIA." ARIA still has a role for custom widgets that HTML cannot express. The rule is to use native HTML first. A later chapter covers this.
- "The default look tells me which element to use." The default look can mislead you. Choose by meaning.
Exercises
Exercise
A designer wants the text "Our team" to appear in large bold type, but it is a short label above a photo and not the title of any section. Which element should you use, and how do you get the large bold look?
Show answer
Use a <p> (or a <span> inside another element) and style it with a CSS class that sets the size and weight. A heading element describes structure, and this label is not a heading, so choosing <h2> only for its size would add a false entry to the heading outline that screen reader users navigate.
Exercise
You inspect a clickable "Save" <div> and a <button> in the Accessibility panel. Name three differences you would expect to see and explain why they exist.
Show answer
The button has the role "button", while the div has a generic role. The button is focusable and part of the tab order, while the div is not unless tabindex is added. The button's accessible name comes from its text and it responds to Enter and Space, while the div does nothing from the keyboard. These differences exist because the browser attaches meaning and built-in behavior to the native <button> element, and a <div> has none.