Semantic HTML, forms & document structure
Mark up a page with the right landmarks, headings and accessible forms.
By Invicly Tech, , in Frontend with React & Next.js. About 10 minutes to read.
In short
Semantic HTML uses elements that describe meaning, like nav, main and button, instead of generic divs. Browsers, search engines and screen readers rely on that meaning to understand and navigate your page.
Think of it like this: Semantic tags are like labelled folders instead of one big unlabelled pile.
Explained simply
HTML is the text that describes what is on a web page. Every piece of content sits inside a tag, like p for a paragraph. Semantic HTML means picking the tag whose name matches what the content is: a navigation menu goes in nav, the main content goes in main, a clickable action is a button.
Why does the name matter if the page looks the same? Because people are not the only readers. Screen readers (software that reads pages aloud for blind users), search engines and browser features like reader mode all read the tags to understand the page. A page built only from div tags looks fine but tells them nothing.
Think of a book. It has a cover, a table of contents, chapters with titles and an index. You can find things because the parts have clear jobs. Semantic HTML gives your page the same parts, so every visitor and every tool can find their way around.
Forms are where this pays off most. A real label tied to an input means clicking the label focuses the field, and screen readers announce the field's name. Input types like email or number give phones the right keyboard and give you free checks before any JavaScript runs.
Press Play on a diagram to walk through it one step at a time.
- header
- logo
- nav
- main
- h1
- section
- article
- form
- aside
- related links
- footer
- contact
- copyright
- div class="header"
- div onclick for actions
- Bold text as fake headings
- Placeholder used as label
- No landmarks to jump to
- header, nav, main, footer
- button for actions, a for links
- h1 to h3 in outline order
- label tied to each input
- Screen readers list the regions
- User to Browser: Clicks Create account1Clicks Create account
- Browser to User: Invalid field: focus it and show a message2Invalid field: focus it and show a message
- User to Browser: Fixes the field and submits again3Fixes the field and submits again
- Browser to Server: All checks pass: POST form data4All checks pass: POST form data
- Server to Browser: Validates again, returns success or errors5Validates again, returns success or errors
- Browser to User: Shows the result page6Shows the result page
In depth
The accessibility tree
The browser turns your HTML into two trees. The DOM is what you style and script. From it, the browser builds a second, smaller tree called the accessibility tree. Each node there has a role (button, link, heading), a name (the text a user hears) and a state (checked, expanded, disabled).
Screen readers never see your CSS. They read only this tree. A button element with the text Save becomes role button, name Save. A div with class btn and the text Save becomes plain text with no role, so a blind user does not know it can be clicked. Semantic tags fill the accessibility tree correctly for free.
- Role: what the thing is
- Name: what it is called
- State: its current condition
- You can inspect it in Chrome DevTools under Accessibility
- Role: button
- Name: Save
- Reachable with Tab
- Announced as "Save, button"
- Role: none (plain text)
- Name: just the text Save
- Skipped by Tab
- Not announced as clickable
Headings are a table of contents
Screen reader users often jump from heading to heading to skim a page, the way you scan bold titles. So heading levels should form an outline: one h1 for the page topic, h2 for main sections, h3 for parts inside an h2.
Pick the level by meaning, then use CSS to set the size. If a design needs a small-looking h2, style it small. Skipping from h2 to h4 because h4 "looks right" leaves a gap in the outline and confuses people who navigate by headings.
- h2: first main section
- h3: part of it
- h3: another part
- h2: second main section
- h3: part of it
- h2: third main section
Native form validation
The browser can check form fields before submit. Attributes such as required, type="email", min, max, minlength and pattern tell it the rules. When the user submits, the browser blocks the submit, focuses the first bad field and shows a message in the user's language.
This is a nice first layer, but it is not security. Anyone can turn it off or send a request directly. Always validate again on the server. You can also style fields with the :invalid and :user-invalid pseudo-classes, and add novalidate to the form if you want to show your own messages with JavaScript instead.
- required: field must not be empty
- type="email" / "url": checks the format
- min / max: limits for numbers and dates
- pattern: a regular expression the value must match
When to use div and span
Div and span are not bad. They are neutral boxes with no meaning, and that is exactly right when you only need a wrapper for layout or styling, such as a flex container around two cards. The rule is simple: if a semantic element describes the content, use it; if nothing fits, use div (block) or span (inline). Problems start only when div replaces something that has a real tag, like a button, link, list or heading.
Learn it in 4 short steps
About 1h each. Track them with a timer in your plan.
- 1Use landmarks like header, main, nav~1h
- 2Structure content with correct headings~1h
- 3Build forms with labels and fieldsets~1h
- 4Use native inputs and validation attributes~1h
Key points
- Use landmarks like header, nav, main and footer so assistive tech can jump between regions.
- Use one h1 per page and never skip heading levels for styling.
- Every input needs a label; group related inputs with fieldset and legend.
- Native elements like button and input type=email give keyboard and validation support for free.
Key terms
Tap a card to flip it. 0/5 known
Examples
<main>
<h1>Sign up</h1>
<form>
<fieldset>
<legend>Your details</legend>
<label for="email">Email</label>
<input id="email" type="email" required />
<label for="age">Age</label>
<input id="age" type="number" min="13" />
</fieldset>
<button type="submit">Create account</button>
</form>
</main>Landmark, heading, labelled inputs and native validation.
Fixing a div-based blog page
Start with a page made of divs: a top bar, a menu, a post and a sidebar. Step 1: wrap the top bar in header and the menu links in nav with a ul list. Step 2: put the post inside main and article, and turn the bold title into an h1. Step 3: subheadings in the post become h2. Step 4: the sidebar becomes aside, and the bottom becomes footer. The page looks identical, but a screen reader can now list 5 regions and an outline of headings.
<header>
<a href="/">My Blog</a>
<nav aria-label="Main">
<ul><li><a href="/posts">Posts</a></li><li><a href="/about">About</a></li></ul>
</nav>
</header>
<main>
<article>
<h1>Learning CSS Grid</h1>
<h2>Why Grid?</h2>
<p>...</p>
</article>
</main>
<aside>Related posts</aside>
<footer>(c) 2026</footer>A delivery-time radio group
You need users to pick one delivery slot. Radio buttons with the same name attribute form one group, so only one can be selected. Wrap them in a fieldset and give it a legend, so a screen reader says "Delivery time, Morning, radio button, 1 of 3". Add required to one radio and the browser refuses to submit until a slot is chosen. Arrow keys move between options with no JavaScript.
<fieldset>
<legend>Delivery time</legend>
<label><input type="radio" name="slot" value="am" required /> Morning</label>
<label><input type="radio" name="slot" value="pm" /> Afternoon</label>
<label><input type="radio" name="slot" value="eve" /> Evening</label>
</fieldset>Quick reference
- One h1 per page; go h1 > h2 > h3 without skipping levels
- Actions use button; navigation to another URL uses a with href
- Landmarks: header, nav, main (only one), aside, footer
- Every input needs a label: for="id" or wrap the input inside the label
- Group related controls with fieldset + legend (radios, checkboxes, address)
- button inside a form defaults to type="submit"; use type="button" for other actions
- Browser validation helps users; server validation protects you
Common mistakes
- Using a clickable div instead of a button, which breaks keyboard access.
- Choosing heading levels for their font size instead of document outline.
- Using placeholder text as a replacement for a visible label.
Quick quiz
Pick an answer to see if you're right and why.
Practice exercises
Try each one yourself first. Use the hint if you get stuck, then compare with the solution.
- Exercise 1easy
Write a newsletter sign-up form with one email field and a submit button. The field must be labelled, required and checked as an email.
- Exercise 2medium
A recipe page has a title, an ingredients list, numbered steps and a "Print" action. Write the semantic HTML skeleton (no CSS).
- Exercise 3hard
Open any website, then in Chrome DevTools open the Accessibility pane and inspect three interactive elements. List any that have no role, a generic role, or an empty name, and say how you would fix each.
Check yourself
Answer in your head, reveal, then be honest with yourself.
Feel confident about this topic?
Frequently asked questions
- Does semantic HTML help SEO?
- Yes, a little. Search engines use headings, links and landmarks to understand structure, but the main benefits are accessibility and cleaner code.
- Can I have more than one header or footer?
- Yes. An article or section can have its own header and footer. Only main should appear once per page.
- What is the difference between section and article?
- An article is self-contained and would make sense on its own, like a blog post or a product card. A section is a themed part of a larger whole and should usually have a heading.
- Is placeholder text enough instead of a label?
- No. Placeholders disappear when you type, are often low contrast and are not reliably announced. Use a visible label and keep the placeholder for an optional hint.