Semantic HTML Explained: Why a Div Is Not a Layout Strategy

Semantic HTML explained with real markup: header, nav, main, article, section, aside, footer, headings, buttons vs divs, and what each element gives you.

Executive Summary: Semantic HTML means choosing elements for what content is, not how it should look. A <button> is focusable, clickable with the keyboard and announced as a button; a <div> with a click handler is none of those until you rebuild each behavior by hand. Landmark elements such as <nav> and <main> let screen reader users jump around a page, and a clean heading outline lets everyone skim it. Layout belongs in CSS; structure and meaning belong in HTML.
Wireframe of a page built from header, navigation, main and footer elements

Inspect the markup of a typical single-page app and you will find something like <div class="header"><div class="nav"><div class="nav-item" onclick="go('/pricing')">Pricing</div>. It looks fine. It also cannot be reached with the Tab key, is not announced as a link, does not open in a new tab on middle-click, and is invisible to a screen reader user who asks for a list of the page’s navigation regions.

Semantic HTML is markup that uses elements according to their meaning: a heading is an h1 to h6, a link to another page is an <a href>, an action is a <button>, the main content is <main>. Browsers attach default behavior and an accessibility role to each element, and that role is what assistive technology, search engines, reader modes and translation tools actually consume. A <div> has no role. It is a generic box, which is exactly what it should be used for: grouping things for styling when no other element fits.

What does a div cost you?

Here is a fake button and the real one, side by side:

<!-- A div pretending to be a button -->
<div class="btn" onclick="save()">Save</div>

<!-- A button -->
<button type="button" class="btn" onclick="save()">Save</button>

To make the div behave like the button, you need role="button" so it is announced correctly, tabindex="0" so it can be focused, a keydown handler for both Enter and Space (and Space must fire on key up, not key down, to match native buttons), focus styles, and a way to express the disabled state that also blocks interaction. Most hand-built versions miss at least one of these. The real button needs none of it.

Behavior <div onclick> <button> <a href>
Reachable with Tab No Yes Yes
Activated with Enter No Yes Yes
Activated with Space No Yes No (Space scrolls)
Announced role None Button Link
Open in new tab, copy link No No Yes
Submits a form No Yes, unless type="button" No
Disabled state Manual disabled attribute Not applicable

The table also answers a question that causes endless debate: link or button? If it navigates to a URL, it is a link. If it does something on the current page, such as opening a menu, submitting, deleting or toggling, it is a button. Styling is irrelevant; a link can look like a button and a button can look like a link.

Which elements structure a page?

HTML5 added a set of sectioning and landmark elements so a page’s main regions have names. Screen readers expose most of them as landmarks, and users can jump between landmarks with a single keystroke, the way sighted users glance at a page.

<body>
  <header>
    <a href="/" class="logo">Acme</a>
    <nav aria-label="Primary">
      <ul>
        <li><a href="/features">Features</a></li>
        <li><a href="/pricing" aria-current="page">Pricing</a></li>
      </ul>
    </nav>
  </header>

  <main>
    <h1>Pricing</h1>
    <section aria-labelledby="plans-heading">
      <h2 id="plans-heading">Plans</h2>
      <article class="plan">
        <h3>Team</h3>
        <p>$29 per seat per month.</p>
      </article>
    </section>
    <aside>
      <h2>Need help choosing?</h2>
      <p><a href="/contact">Talk to sales</a></p>
    </aside>
  </main>

  <footer>
    <p>&copy; 2023 Acme Inc.</p>
  </footer>
</body>
Element Use it for Notes
<header> Introductory content for the page or a section A landmark only when it is the page header, not inside an article or section
<nav> Major blocks of navigation links Label each one when there are several: “Primary”, “Footer”, “Breadcrumb”
<main> The page’s unique primary content One visible main per page; the target of a skip link
<article> Self-contained content that would make sense on its own Blog posts, product cards, comments, forum posts
<section> A thematic grouping with its own heading Not a generic wrapper; if it has no heading, it is probably a div
<aside> Content tangential to what surrounds it Sidebars, pull quotes, related links
<footer> Closing information for the page or a section Page footer is a landmark; an article’s footer is not

<section> is the most misused of these. It is not a semantic div. The test is simple: does this block have a heading that names it, and would it appear in a table of contents? If yes, use section. If you just need a wrapper for a background color, use div.

How do headings form the outline?

Screen reader users navigate by headings more than by anything else; surveys of screen reader users by WebAIM have consistently found headings to be the most common way people find information on a long page. Sighted readers skim the same way, just visually. So the heading levels must describe the structure, not the font size:

  • One h1 that names the page.
  • h2 for each major section, h3 for subsections inside them.
  • Do not skip levels on the way down; jumping from h2 to h4 suggests a missing section.
  • Do not pick a level for its size. If you want a small h2, style it with CSS.
  • Do not use headings for things that are not headings, such as a bold sentence in a card or a big number in a stats block.

One myth to drop: the “document outline algorithm”, under which each section would restart heading levels at h1, was written into early HTML5 drafts but never implemented by any browser or screen reader. Pages that used h1 inside every section ended up with a flat outline of many h1s. Use explicit levels.

The small semantic elements that pay off

  • <time datetime="2023-01-31">31 January</time> gives machines an unambiguous date while humans read whatever format you like.
  • <figure> with <figcaption> associates a caption with an image, chart or code sample.
  • <ul> and <ol> make screen readers announce “list, 5 items”, which tells users how much is coming. Navigation menus, card grids and tag lists are all lists.
  • <table> with <th scope> for tabular data, never for layout, and never replaced with a grid of divs when the data really is tabular.
  • <address> for contact information about the page or article author, not for any postal address.
  • <em> and <strong> for stress and importance; <i> and <b> for text set apart without extra importance, like a term or a product name.
  • <mark> for highlighted text, such as search matches.

Who else reads your markup?

Accessibility is the strongest reason for semantic HTML, but not the only one.

  • Browser reader modes in Safari, Firefox and Edge use article, main and headings to decide what to keep.
  • Search engines parse headings and main content to understand what a page is about, and real links to discover other pages. A div with an onclick handler is not a link a crawler follows.
  • Browser features such as autofill, translation, “copy link”, middle-click and long-press menus all depend on native elements.
  • Your future self. <nav> and <footer> are easier to scan in a code review than <div class="wrapper-3">.

When is a div the right answer?

None of this means divs are bad. A div is the correct element when you need a box purely for layout or styling and no element describes the content: a flex wrapper around two columns, a card’s inner padding container, a grid row. CSS Grid, which I wrote about in web design with CSS Grid layout, reduced how many wrappers you need, but some will always remain. The problem is never the div itself. It is using a div where a more meaningful element exists, and especially using one for anything interactive.

A quick audit you can run today

  1. Unplug the mouse and Tab through the page. Every interactive thing should be reachable, show focus, and work with Enter or Space.
  2. Open the accessibility tree in Chrome or Firefox DevTools and check that buttons say “button”, links say “link”, and the landmarks you expect exist.
  3. Use a headings extension or the screen reader’s heading list. Does the outline make sense with no other context?
  4. Search your code for onclick on div and span elements. Each one is a candidate for a button or a link.
  5. Run the page through the W3C validator to catch invalid nesting, which often breaks semantics silently.

Frequently Asked Questions

What is semantic HTML?

Semantic HTML is markup that uses elements according to their meaning, such as headings for headings, nav for navigation, button for actions and a for links. Browsers attach built-in behavior and accessibility roles to these elements, which assistive technology, search engines and browser features rely on.

Does semantic HTML help SEO?

It helps search engines understand a page: headings describe the topic and structure, main content is easier to identify, and real links let crawlers discover other pages. It is not a ranking trick on its own, but poor markup can hide content and links from crawlers.

When should I use section instead of div?

Use section for a thematic group of content that has its own heading and would belong in a table of contents. If the block has no heading and exists only for styling or layout, use a div.

Use a link when the action navigates to a URL, and a button when it performs an action on the current page, such as submitting a form or opening a menu. Choose by behavior, not appearance; CSS can make either look like the other. For the styling side, start with the CSS box model, display, and positioning.

Meaning first, layout second

Start every component by asking what the content is, pick the element that says so, and only then reach for a div to hold the layout together. The browser gives you keyboard support, roles and landmarks for free when you do; when you do not, you are signing up to rebuild them by hand. Elements flow on the page in two basic ways, which I explain in block, inline and the flow of the document, and every page rests on the document skeleton. For the full reference, see MDN on semantics in HTML and web.dev’s semantic HTML lesson. Related reading on this site: ARIA landmarks and accessible forms.

Originally posted on 31 January 2023 and post last modified on 31 January 2023

Accessibility Front-End Development HTML Elements HTML5 Landmarks Semantic HTML

Share this article

Leave a Reply

Your email address will not be published. Required fields are marked *