HTML Semantics: The Interview Answer
Why semantic HTML matters, how it affects accessibility/SEO, and how to choose the right elements.
On this page
30‑second interview answer
Semantic HTML means using elements that describe the meaning of content—<button>, <nav>, <main>, <article>—instead of generic <div>s. Semantics improves accessibility (screen readers, keyboard behavior), SEO, and maintainability. Prefer native elements first; use ARIA to fill gaps, not to replace semantics.
Why semantics matters (real reasons)
- Accessibility
- Screen readers use semantics to announce role and structure.
- Native elements come with keyboard behavior for free (e.g.,
buttonis focusable and clickable with Enter/Space).
- SEO & discovery
- Search engines understand page structure better.
- Maintainability
- Future devs can understand intent instantly.
The most common interview examples
button vs div for clickable UI
Bad:
<div onclick="doThing()">Save</div>Problems:
- not keyboard accessible by default
- role is unclear
- needs ARIA + tabindex + key handlers
Good:
<button type="button">Save</button>Page landmarks
Good structure:
<header>...</header>
<nav>...</nav>
<main>
<article>...</article>
</main>
<footer>...</footer>Headings: structure matters
Rules of thumb:
- Use one
h1for the page/topic. - Don’t skip heading levels for visual styling.
- Use CSS for size, not heading level.
Forms: use the right attributes
- Always connect labels to inputs:
<label for="email">Email</label>
<input id="email" name="email" type="email" />- Use
button type="submit"inside forms. - Use correct input types (
email,tel,url) for better mobile keyboards.
ARIA: the interview-safe stance
- Prefer native semantics.
- If you must build a custom control, add:
- correct
role - keyboard handling
- focus management
- ARIA states (
aria-expanded,aria-controls, etc.)
- correct
Interview line:
“No ARIA is better than bad ARIA. Native elements first.”
Common traps
- Using
divfor everything - Click handlers on non-interactive elements without keyboard support
- Missing
alton images (or meaningless alt) - Using headings for styling
Mini Q&A
Q1: Why is semantic HTML important?
- Accessibility + SEO + maintainability.
Q2: When do you use ARIA?
- When native elements can’t express the needed behavior.
Q3: button vs a?
anavigates;buttonperforms an action.
Summary checklist
- I use native elements for intent.
- I can explain landmarks and headings.
- I know ARIA is a last resort.
- My UI is keyboard accessible by default.
Looking for structured, offline interview prep?
Free online lessons • Portable Amazon Kindle / Paperback
Frontend Interview Guide (2025 Edition)
By Rajesh Dhiman
Comprehensive preparation covering React internals, Web Performance, CSS architecture, and system design questions.
JavaScript Interview Guide
By Rajesh Dhiman
Deep dive into the Event Loop, microtask draining, closures, prototypal inheritance, and asynchronous execution patterns.
Note: All lessons on Frontend Interview remain completely free to read online. As an Amazon Associate, we may earn from qualifying purchases.
Written by Rajesh Dhiman
Authored by Rajesh Dhiman and engineered at Eunix Tech. Focused on deep-dive frontend engineering, JavaScript runtime internals, React architecture, and web performance.