Testing HTML means checking that a page is valid, accessible, renders the same across browsers and behaves correctly when scripts run. You do it with a mix of markup validators, accessibility audits, browser developer tools and automated end-to-end tests. Running these checks before every release catches broken markup long before users see it.
This tutorial walks through a practical HTML testing workflow you can set up in an afternoon, using free and widely supported tools.
Browsers are forgiving. They repair unclosed tags, ignore unknown attributes and still paint something on screen. That tolerance hides real problems: a missing alt attribute, a form field without a label or a duplicated id may look fine in your browser and still break for screen reader users, search crawlers or older devices.
A good test routine checks four things:
| Area | What you verify | Typical tool |
|---|---|---|
| Validity | Markup follows the HTML living standard | Nu Html Checker (W3C validator) |
| Accessibility | Roles, labels, contrast, keyboard use | axe, Lighthouse, browser accessibility tree |
| Rendering | Layout across browsers and screen sizes | Browser dev tools, Playwright |
| Behaviour | Forms, links and scripts do what they should | Playwright, Cypress |
Begin every test from a known-good document. This page passes the validator with no warnings:
Notice the pieces that tests commonly flag when they are missing: the lang attribute on <html>, the character encoding, a <title>, a single <h1>, and a <label> connected to its input through for and id.
The Nu Html Checker is the validator behind validator.w3.org. You can paste a URL, upload a file or run it locally in a build step. It reports errors such as stray end tags, invalid nesting and attributes that do not exist on the element.
For a project with many pages, run it in continuous integration. The html-validate package is a popular command line alternative:
Fix errors first, then warnings. Treat a failing validation step like a failing unit test and block the merge.
Automated checks catch roughly the mechanical half of accessibility problems: missing labels, low colour contrast, invalid ARIA and empty links. They cannot judge whether alt text is meaningful, so pair them with a manual pass.
Manual checks do not scale. Playwright runs the same scenario in Chromium, Firefox and WebKit. This test loads the page above, fills the form and checks the accessibility basics:
Because the test finds elements by label and role, it fails if the label or the semantics break, which is exactly the regression you want to catch. Run it with npx playwright test.
Use the device toolbar in browser developer tools to check small screens, then add projects to the Playwright configuration so every run covers a phone and a desktop viewport. Verify that text stays readable without zooming, nothing overflows horizontally and tap targets are large enough to hit.
No search engine requires perfect validity, but broken structure such as missing titles, unclosed elements or duplicate headings can confuse crawlers and hurt how a page is understood. Validation is a cheap safeguard.
Test in the current Chromium, Firefox and Safari (WebKit) engines. Playwright covers all three, which is enough for the large majority of users.
No. Tools find missing labels and contrast failures, but only a person can judge reading order, clear wording and real keyboard and screen reader usability.
A unit test checks a small piece, such as a template function that produces markup. An end-to-end test loads the full page in a real browser and interacts with it like a user.
Test HTML in layers: validate the markup, audit accessibility with automated tools and a keyboard pass, then lock in behaviour with a Playwright suite that runs in continuous integration. Start from a valid, semantic page and every later check becomes easier to pass and easier to trust.