Semantic HTML: Structure as Accessibility Infrastructure
Semantic HTML assigns real roles to page elements so screen readers can navigate them. Use buttons for actions, headings for outline, and tables for data. The footgun is using divs with click handlers as buttons; they are invisible to keyboard and screen…
Why it exists
The web began as a document system where markup carried meaning. When developers replace meaningful tags with generic containers, browsers and assistive technologies lose the structural map they need to present content to users who cannot see the screen. Semantic HTML preserves that map without extra JavaScript or ARIA by using the right element for the right purpose.
The mental model
Think of HTML tags as the architectural blueprint of a building. A div is an unmarked room, a button is a door with a handle, and a nav is a hallway sign. Screen readers and keyboards navigate by reading those signs. When you use the wrong tag, you are hanging a picture over a door and expecting visitors to know it opens. The browser supplies behavior, focus management, and announcements for free when you pick the native element that matches your intent.
How it works
Every HTML element has an implicit role in the accessibility tree that the browser exposes to assistive tech. A button element is focusable, clickable with Enter or Space, and announced as a button. A heading element creates a navigable outline. A table element exposes row and column relationships. When you use a div with an onClick handler instead, none of that happens unless you manually add tabindex, key listeners, and ARIA roles. Native semantics do the work for you.
When to use it
Use semantic elements whenever the content matches their purpose. Use button for clickable actions, a for navigation links, h1 through h6 for document outline, nav and main for page regions, ul and ol for lists, and table for tabular data. Use landmark regions so screen reader users can jump directly to content without tabbing through every interactive element. Use label elements explicitly tied to inputs so form fields announce their purpose.
When not to use it
Do not use a heading tag just because you want large bold text; that pollutes the outline and disorients screen reader users who navigate by heading. Do not wrap everything in divs and add ARIA as a retrofit; ARIA is powerful but fragile, and native HTML is more robust. Do not choose a tag based on its default browser styling rather than its meaning. If the semantics do not fit, that is when you reach for ARIA, not before.
One canonical example
Imagine a modal dialog. The correct pattern uses a button to open it, a dialog element or a div with role dialog, a focus trap, and an h2 for the title. The dialog element itself handles focus management and backdrop behavior in modern browsers. If you instead build it from nested divs with CSS positioning, you must rebuild focus trapping, Escape key handling, and screen reader announcements from scratch. A single dialog tag replaces dozens of lines of accessibility code.
Interview question
What is the primary accessibility drawback of using a div with an onClick handler instead of a native button element?
- a.The element loses its ability to trigger JavaScript click events unless a tabindex attribute is added.
- b.The div becomes invisible to screen readers and is completely skipped during navigation.
- c.The developer must manually rebuild focus management, keyboard activation, and screen reader announcements that native buttons receive automatically.Correct
- d.The browser automatically exposes the div as a button to assistive technologies because it detects the onClick handler.
Why? this is the answer
The card explains that a native button is automatically focusable, clickable with Enter or Space, and announced as a button, whereas a div with onClick lacks all of these unless the developer manually adds tabindex, key listeners, and ARIA roles. Option B is tempting because the summary mentions divs are invisible to keyboard and screen, but the detail clarifies they remain in the document without native interactive semantics rather than being skipped entirely.
Just read this? Test yourself on what you have been reading.
- #semantic-html
- #accessibility
- #a11y
- #design-systems
- #frontend
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.
See open roles