Back to HTML

How to Validate HTML and Read the Errors

Coding Tutorials Team 26 July 2026

The browser will not tell you when your markup is wrong. It is required by specification to repair whatever it receives and carry on, which means a broken page and a correct page can look identical. A validator is the only tool that reports the difference, and learning to read its output takes about ten minutes.

What validation actually checks

The validator compares your document against the HTML specification and reports every place it deviates. It checks that elements are closed, that nesting follows the content model, that required attributes are present, that ids are unique, and that attributes exist on elements permitted to carry them.

What it cannot check is whether your markup is any good. A page built entirely from divs with no headings will validate cleanly while being poor structure and poor accessibility. Validation is a floor, not a standard of quality.

Three ways to run it

The official validator at the W3C accepts input three ways. You can give it a public address, which is the fastest option for anything already deployed. You can upload a file, which suits pages not yet online. Or you can paste markup directly, which is best for isolating a fragment you suspect.

For pages generated by a server side language, validate the rendered output rather than your template, since the errors usually come from how the pieces were assembled rather than from any one file. Viewing source in the browser and pasting the result is the reliable way to capture that.

Reading the messages

The output looks intimidating and follows a consistent shape: a severity, a line and column, and a description. A few messages account for the large majority of what you will see.

An end tag reported for an element which is not open means your closing tags are out of order, or one was already closed automatically because of invalid nesting. Look upward from the reported line rather than at it.

An unclosed element message points at the opening tag rather than where you noticed the problem, which is genuinely helpful because that is where the fix belongs.

A message about a stray end tag usually means something was closed twice, often after a copy and paste.

Duplicate id values are reported with both locations, and this one is always worth fixing because it breaks scripting and in page links.

A required attribute missing is most often an image with no alt attribute, which is both a validation error and an accessibility failure.

Fix the first error first

This is the single most useful habit. Errors cascade. One unclosed div early in a document can generate dozens of downstream complaints that all disappear the moment the original is corrected. Working from the bottom of the list is how people conclude that validation is hopeless.

Correct the topmost error, run it again, and watch the count drop. Repeating that loop resolves most pages in a handful of passes.

Warnings and what to ignore

Not everything reported carries equal weight. Errors are genuine specification violations and should be fixed. Warnings are advisory and sometimes reflect a stylistic preference rather than a defect. Info messages are usually noise.

Some warnings are worth heeding regardless. A section without a heading suggests your document outline is weaker than you think. A type attribute on a stylesheet link is redundant in modern HTML and can be removed. Conversely, complaints about attributes belonging to a framework are expected if your page is rendered by one, and are not something to act on.

Validate accessibility separately

Because the validator only checks conformance, it will not tell you that your colour contrast is inadequate, that your form inputs have no labels, or that your headings skip levels. Accessibility checkers exist for that and cover ground the validator deliberately does not.

The two are complementary. Valid markup makes accessibility tooling more reliable, because assistive technology works from the same document tree the validator is checking, and a repaired tree can differ from what an audit assumes it is examining.

Make it a habit rather than an event

Validating once at the end of a project produces a long, discouraging list. Validating each page as you finish it produces two or three errors you can fix immediately while the markup is still fresh in your mind. Many editors offer a linting extension that flags problems as you type, which shortens the loop further and catches the unclosed tag before it ever reaches a browser.