Two web pages can look the same in a browser and be built very differently underneath. This guide explains what semantic HyperText Markup Language (HTML) means, which elements to use for the main parts of a page, and why the choice matters for screen reader users, search engines and anyone who maintains your code.
What “semantic” means
The MDN Web Docs glossary entry on semantics defines the term as the meaning of a piece of code. In HTML, that means the purpose or role an element has, rather than what it looks like. The <h1> element, for example, gives its text the role of a top-level heading on the page.
You could style a <span> with a large font so it looks like a heading, but it would still carry no meaning. HTML should describe the content; how it looks is the job of Cascading Style Sheets (CSS).
Step 1: Mark up the main areas of the page
Most websites share the same building blocks: a header, a navigation bar, the main content, often a sidebar, and a footer. MDN’s guide to structuring documents maps each one to a dedicated element:
<header>holds introductory content. As a child of<body>it is the page header; inside an<article>or<section>it is the header for that part only.<nav>holds the main navigation links. Secondary links do not belong in it.<main>holds the content unique to this page. Use it once per page, directly inside<body>.<aside>holds content that is only indirectly related to the main content, such as related links or an author biography.<footer>holds the closing content of the page.
Put together, a simple page skeleton looks like this:
<header>
<h1>City Library</h1>
</header>
<nav>
<a href="/books">Books</a> <a href="/events">Events</a>
</nav>
<main>
<article>
<h2>New reading room</h2>
<p>The reading room on the first floor is now open.</p>
</article>
<aside><h2>Related links</h2></aside>
</main>
<footer><p>Contact the front desk</p></footer>
Step 2: Choose between article, section and div
An <article> wraps content that makes sense on its own without the rest of the page, such as a single blog post. A <section> groups one part of the page around a single function or theme, and MDN calls it best practice to begin each section with a heading. An article can be split into sections, and a section can hold several articles, depending on the content.
When no semantic element fits, HTML gives you two non-semantic wrappers: <div> for blocks and <span> for inline text, ideally with a class name that labels them. MDN warns that divs are so convenient that they are easy to overuse, which clutters the code and makes it harder to maintain.
Step 3: Use real headings, lists and paragraphs
MDN’s article HTML: A good basis for accessibility calls a clear text structure one of the best aids a screen reader user can have. With proper headings, many screen readers let users jump from heading to heading, or bring up a list of all headings and use it as a table of contents.
A page built from styled spans and line breaks gives the screen reader nothing to use as signposts, so it is read out as one giant block. Source order matters too: the content should make sense in the order it appears in the HTML, because that is what screen reader users hear.
Step 4: Use real buttons and links
Interactive elements come with behavior built in. Compare these two lines:
<div>Play video</div>
<button>Play video</button>
The <button> is reachable with the Tab key and can be activated with Space, Return or Enter. The <div> can do none of this. To fake it, MDN’s example has to add tabindex="0", role="button" and extra JavaScript for the Enter key. Links, labels and form controls work the same way: the right element brings keyboard support for free.
Why it matters
MDN lists several benefits of semantic markup. Screen readers use the elements as signposts. Search engines give more weight to keywords inside headings and links than to keywords inside plain divs. Developers find meaningful blocks of code faster. And it takes no longer to write if you use it from the start. The audience is large: MDN notes that roughly 8% of men and 0.5% of women are colorblind, and that blind and visually impaired people make up roughly 4 to 5% of the world population.
Common mistakes
- Choosing elements for their default look. Pick a heading level for its place in the page structure, not its size, and change the size with CSS.
- Using more than one main.
<main>marks the content unique to the page and belongs there once. - Building buttons from divs. You lose keyboard support and default styling, and have to rebuild both by hand.
- Spacing text with line breaks.
<br>is for fixed short lines, such as a postal address or a poem, not for separating paragraphs.
Before you type a tag, ask the question the MDN glossary suggests: which element best describes the content you are about to add? Is it a list, a self-contained article, a figure that needs a caption? Answer that first, use <div> only when nothing else fits, and leave the look to CSS. Your pages will be easier to navigate, easier for search engines to read and easier to maintain.


