Testing HTML means checking three things before a page ships: the markup is valid, it is accessible, and it behaves the same in the browsers you support. You can cover most of this with a validator, an accessibility checker and a few automated browser tests that run on every commit.
This tutorial gives you a practical checklist and a small automated setup you can reuse on any static page or web app.
HTML is forgiving. Browsers repair broken markup silently, so a page can look fine and still contain errors that hurt search ranking, screen reader users or script behaviour. A useful test plan covers these areas:
| Area | What goes wrong | How to check |
|---|---|---|
| Validity | Unclosed elements, duplicate id values, invalid nesting | W3C Nu HTML Checker |
| Accessibility | Missing labels, no alt text, low contrast, no landmarks | axe-core, Lighthouse |
| Semantics | <div> used instead of <button>, <nav>, <main> | Code review, linting |
| Rendering | Layout differs between engines | Playwright on Chromium, Firefox, WebKit |
| Behaviour | Forms, dialogs and links do not work | End-to-end tests |
Start from a document that passes validation, so any later error is one you introduced.
The page declares the document type, the language, the character set and a viewport, uses landmark elements (<header>, <nav>, <main>, <footer>), and ties the input to its label with for and id.
The W3C Nu HTML Checker is the reference validator for the HTML living standard. You can paste markup into the online checker, or run it locally through the vnu-jar npm package.
An empty output means no errors. Typical findings are a <li> outside a list, a block element inside <p>, an attribute that does not exist on the element, or an id used twice. Fix errors first, then read warnings and decide which matter.
Automated tools find roughly the mechanical problems: missing names, bad ARIA, contrast failures. They cannot judge whether a page is understandable, so treat them as a floor, not a finish line.
Install axe-core through Playwright and fail the test when it reports violations:
Follow this with a manual pass: tab through the page with the keyboard, confirm the focus outline is visible, and try a screen reader on the main flow.
Playwright runs the same test in Chromium, Firefox and WebKit, which covers the three engines behind nearly all browsers in use.
Selecting by role and label, as above, doubles as an accessibility check: if the test cannot find the button by its accessible name, a screen reader user will not find it either.
Run all tests with:
Run the validator and the browser tests on every pull request so regressions are caught before merge. A minimal GitHub Actions job:
Serve the pages locally in the Playwright configuration (the webServer option) so the job needs no external host.
No. Validity only proves the syntax is correct. A valid page can still be unusable with a keyboard or a screen reader, so combine the validator with accessibility and behaviour tests.
Yes. Engines differ in form controls, date inputs, scrolling and newer CSS features. Playwright makes the three-engine run cheap.
axe-core and Lighthouse both report them. Axe integrates well into automated tests, while Lighthouse also reports performance and SEO.
Validate the HTML your server sends, and run behaviour and accessibility tests against the rendered DOM in a real browser. Scripts can change the DOM after load, so both views matter.
Test HTML in layers: validate the markup with the Nu HTML Checker, scan for accessibility problems with axe-core, and verify behaviour in Chromium, Firefox and WebKit with Playwright. Add a manual keyboard pass, and run the automated layers in CI so every change is checked.