Semantic and Accessible HTML

Choose elements for their meaning so pages are navigable by screen readers, keyboards and search engines out of the box.

Beginner · about 4 hours · difficulty 2/5

Learn first: HTML Document Essentials

Semantic HTML means picking the element whose meaning matches the content. A <button> is focusable, activates on Enter and Space, and announces itself as a button. A <div onclick> does none of that until you rebuild it by hand. Semantics are the cheapest accessibility you will ever get.

Landmarks and structure

  • <header>, <nav>, <main> (once per page), <aside>, <footer> create landmarks screen reader users jump between.
  • <article> is self-contained content; <section> is a themed group, ideally with a heading.
  • A logical heading outline (one <h1>, then <h2>s) is how many users skim a page.

Accessibility basics baked into HTML

  • Every image needs an alt: describe the purpose, or use alt="" for purely decorative images.
  • Links say where they go ("Download the 2024 report", not "click here").
  • Buttons do things, links go places. Do not swap them.
  • Set lang on <html> so screen readers use the right pronunciation.
  • Associate every form control with a <label>.
  • Use <details>/<summary> and <dialog> for native disclosure and modal patterns.

The first rule of ARIA

If a native element exists, use it instead of adding ARIA roles to a <div>. ARIA changes what is announced but adds no behaviour.

Good enough to move on

Navigate your own page with only the keyboard (Tab, Shift+Tab, Enter, Space), and use a screen reader's landmark or heading list once (VoiceOver rotor or NVDA elements list). If everything is reachable and makes sense, your semantics are sound.

Key concepts

  • Landmark elements: header, nav, main, aside, footer
  • article vs section vs div
  • Heading outline
  • Meaningful alt text
  • Buttons vs links
  • details, summary and dialog
  • First rule of ARIA
  • Keyboard-only smoke test

Mini project

Take a div-soup landing page (write one or find one) and refactor it to semantic HTML with landmarks, a proper heading outline, real buttons and labelled images; verify with a keyboard-only walkthrough.

Check yourself

What does a native button give you for free that a div with a click handler does not?

Free resources