Writing Maintainable HTML
Habits that keep markup easy to change: native elements first, structure from content, few wrappers, unique ids, validation in CI, and a checklist for review.
HTML Validation and DebuggingHTML Email and Legacy Constraints
Writing Maintainable HTML
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- Maintainable HTML is HTML where the element says what the thing is. A `button` needs no comment, class or script to explain that it is a button.
- Start from the content and its structure, not the visual design: headings, lists, landmarks, then wrappers only where layout needs them.
- A native element carries behaviour you would otherwise rewrite and keep in sync: in tests, a `div` styled as a button had no role and no keyboard activation, and a `div` with a click handler was invisible to axe.
- Unique ids, valid nesting and real labels are mechanical rules, so let tools enforce them. The Nu validator found nesting errors, a duplicate id and an `alt`-less image in a short file.
- Pick conventions (lowercase tags, quoted attributes, a class naming scheme, heading order) and apply them consistently, because consistency is what a reader or reviewer relies on.
Why HTML ages badly
Maintainable HTML means someone can change a page months later without breaking it. HTML looks like the easy layer, so it gets written fast and never revisited: a nest of divs, classes named after how things looked, an onclick here, a copied block there. Then a redesign arrives and every one of those choices has to be reverse-engineered.
Most of the cure comes from earlier lessons, put into habits.
1. Native elements first
Every native element packs behaviour and meaning that you’d otherwise rebuild. The evidence is in the accessibility lessons: a clickable div came out as a generic node, a div role="button" was in the tree but ignored Enter and Space, and a real button was a button, focusable and keyboard-activatable. See the accessibility tree, focus and ARIA. The same applies up the ladder: details over a hand-rolled accordion, dialog over a modal library. A native element is code you don’t maintain. Think of it as buying the standard part rather than machining your own.
Choose links and buttons by job: a link goes somewhere; a button does something.
2. Structure from the content
Begin from what the page says. Write the headings, lists and landmarks, as in landmarks and sections, then add layout wrappers where CSS needs them. Starting from the design produces a div for every box, and the outline falls out wrong. Keep heading levels in order, since a skipped level was flagged by both the validator and axe in tests. The frontend roadmap’s semantic HTML lesson says the same from the survey angle.
div and span are not bad. They are the right choice when nothing else describes the thing, which is why the generic containers lesson puts them last in the list.
3. Few wrappers, honest names
Each wrapper is something a future editor must understand and a browser must lay out (rendering cost). Remove ones that exist only from habit. Name classes for what a thing is (.price, .card), not how it looks (.red-bold), so a redesign doesn’t contradict the markup. A naming scheme such as BEM helps teams stay consistent; the CSS architecture lesson covers it.
4. Let tools hold the rules
Some rules are mechanical, and tools should enforce them:
- Validation. The Nu validator on a short messy file reported a
divin aspan, a stray</p>, abuttoninside a link, an image with noalt, a duplicate id, adivin auland an obsolete element. Run it in CI (validation and debugging). - Accessibility rules. axe found nine rule violations on a small page (testing).
- Formatting. A formatter ends arguments about indentation and attribute order.
Tools have limits. In my runs, neither the validator nor axe flagged a <div role="button"> that couldn’t be used from the keyboard. Review and manual tests do that work.
5. Decide conventions, then keep them
Lowercase tags and attributes, double-quoted values, one lang on the root, alt on every image, labels tied to inputs, ids unique and used for anchors and labels rather than styling, comments that say why and not what. Which convention matters less than that the whole codebase uses one. Templates and custom elements help by letting one copy of a pattern serve the whole site.
A review checklist
- Is each interactive thing a native control?
- Do headings form a sensible outline?
- Does every control have a name, and every image meaningful
altoralt=""? - Are there wrappers that could go?
- Does it validate and pass an automated accessibility scan?
- Can you do everything with a keyboard?
What the video covers
This is a clip, 19:47 to 58:21, of Scrimba’s livestream “Don’t write bad HTML - with Manuel from HTMHell” (July 2022, about 61 minutes), with Manuel Matuzović. The description says he shows HTML do’s and don’ts, with validation and accessibility features. The clip’s chapters are: how to turn a design mockup into an HTML document, breaking down a design’s structure, a second example, whether a pulsing icon would signal a button, choosing anchors or buttons, whether head components matter for low-traffic sites, what text belongs in HTML versus JavaScript, whether divs are bad, whether sections are bad, and sections versus articles. The first 20 minutes, on accessibility testing and tools, are left out of the clip (the earlier a11y lessons cover them). It is a long, conversational stream with Q&A, and I could not read a transcript. There is no tight short video on this node, so this is the best honest fit I found.
Where this fits
This closes the batch’s three groups and the roadmap’s production group, after HTML email. It leans on validation most, and ties the earlier semantics, accessibility and interactive lessons together.
Check yourself
When is `<div>` the right element?
When no element describes the thing and you need a wrapper for layout or a script hook. A `div` has no meaning, so use it last. Check first for `nav`, `main`, `section`, `ul`, `button`, `figure` and the rest.
Why start from the content outline instead of the design mockup?
The outline gives you headings, lists and landmarks, which are what screen readers, search engines and future editors read. Visual wrappers come second, and only where the layout truly needs them.
A teammate styles a `div` with a click handler as a button. What is missing?
A role, focus, Enter and Space activation, a disabled state, and form behaviour. In tests the `div` appeared as a generic node, a `role="button"` version ignored Enter and Space, and axe did not flag either. Use a `button`.
What can you automate for HTML quality?
Validation (nesting, duplicate ids, missing `alt`, obsolete elements), an accessibility rule engine like axe, and a formatter or linter for style. They do not replace review, since neither of those tools flagged a `div role="button"` with no keyboard support.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.