To check HTML code for errors, paste the whole document into the W3C validator at validator.w3.org, open the "Validate by Direct Input" tab and press Check. It lists every error with a line and column number; fix the first few, then check again.
A validator tests your markup against the HTML rules and tells you where you broke them. A browser will not do that for you, because browsers quietly repair bad markup instead of reporting it.
Why the browser does not show you HTML errors
Browsers parse HTML permissively. The HTML Standard defines how a parser must recover from malformed input, so a missing closing tag or a stray character does not stop the page from rendering. MDN explains that this was a deliberate choice on the early web: getting content published mattered more than strict syntax.
The drawback is that the browser's repair is not always what you meant. MDN gives this example of badly nested tags:
<strong>strong <em>strong emphasized?</strong> what is this?</em>
The browser rewrites it so that the <em> element closes early and a second <em> starts after the </strong>. The text displays, but the structure in the browser is different from the structure in your file. That gap is where odd styling and scripts that select the wrong element come from. If you are still learning how the three web languages fit together, see HTML, CSS and JavaScript: How They Work Together.
How to check HTML with the W3C validator
These steps follow MDN's debugging guide:
- Open the W3C Markup Validation Service at
https://validator.w3.org/. - Switch to the Validate by Direct Input tab.
- Paste the entire document, including
<!doctype html>,<html>and<head>, not only the contents of<body>. - Press Check.
- Read the messages. Each one includes a line and column number.
- Fix a few errors, then check again. Stop when the page reports: "Document checking completed. No errors or warnings to show."
The service also accepts a page address, which is the quickest option for a page that is already online. The page must be reachable from the internet, so a site running on your own computer cannot be checked by address. Paste its source into the Direct Input tab instead, or use the local tool described below.
The validator also has an option to clean up markup with HTML-Tidy. Its help page warns that there are no guarantees about the validity or other aspects of that output, so treat it as a hint and make the fix in your own file.
What the common error messages mean
MDN lists the messages the validator produced for a small test page with deliberate mistakes. These are the exact messages and what they point to:
| Message | What it usually means |
|---|---|
End tag li implied, but there were open elements | An element inside the list item is still open. The reported position is the line after where the closing tag belongs. |
Unclosed element strong | The <strong> was never closed. The position points at its opening tag. |
End tag strong violates nesting rules | Two elements overlap instead of nesting, as in the <strong> and <em> example above. |
End of file reached when inside an attribute value. Ignoring tag | An attribute value was opened but never closed, usually a missing closing quote. MDN calls this message cryptic. |
End of file seen and there were open elements | Elements are still open when the file ends. A missing attribute quote can cause it, because the rest of the document is swallowed into the attribute. |
The last two show why the reported element is not always the culprit. In MDN's example, a missing quote in a link's href makes the validator report Unclosed element ul, even though the <ul> is closed correctly. The real problem was the unclosed <a> attribute. When a message names an element that looks fine, check the attributes and tags just before it.
Fix the first errors first
The W3C help page warns that one error can confuse the validator so much that it cannot make sense of the rest of the page. MDN calls this a domino effect. In practice:
- Work from the top of the report downward and fix only the first two or three errors.
- Check again before touching anything else. Many of the remaining messages usually disappear.
- If a message makes no sense, look at the line above the one it reports. Unclosed elements and missing quotes are reported where the parser noticed the problem, not where you made it.
Two other problems the W3C help page calls out as common are a missing DOCTYPE and a missing character encoding declaration. The fix for the first is the plain HTML5 declaration <!doctype html> on the first line. For the second, declare the encoding in the head, for example <meta charset="utf-8">.
Check HTML files locally with vnu.jar
The checker behind the web service is the Nu Html Checker, and you can run your own copy. It needs no browser and can check a whole folder, which suits a site with many pages. The project's GitHub page gives this form:
java -jar ~/vnu.jar [OPTIONS]... FILES|DIRECTORY|URL...
Replace ~/vnu.jar with the path to the jar file. As of the project page, vnu.jar needs Java 17 or later. The pre-compiled Linux, Windows and macOS binaries include their own Java runtime, so they need no separate install. Other ways to get it are npm install vnu-jar, brew install vnu, and a Docker image that checks a mounted folder:
docker run --rm -v /var/www/html:/data ghcr.io/validator/validator:latest vnu --skip-non-html /data
Replace /var/www/html with the folder that holds your HTML. The full list of options is in the project's docs/vnu.1.md, so read that rather than guessing flags. The project also lists a Grunt plugin and a Gulp plugin for running the check as part of a build.
What a validator cannot tell you
A clean result means the markup follows the rules. It does not mean the page is good. The W3C help page says a valid web page is not necessarily a good web page, and that some conformance requirements cannot be expressed in the grammar the validator checks against. The Nu Html Checker's own About page describes it as a checker "intended solely" for finding mistakes, not a pass/fail certification, and says its behaviour may change, so a zero-error result today is not a guarantee for later.
It will not tell you whether your CSS works, whether your JavaScript throws errors, or whether a link points to the right page. For those, use the browser's developer tools and test the page by hand. What the validator does well is the thing the browser hides: unclosed elements, overlapping tags, broken attributes and missing declarations.
If the validator reports errors you cannot find
Check that you pasted the complete document. A fragment without a DOCTYPE or <html> element produces errors about missing structure that are not real problems in your full page. If the page is built by JavaScript or a template, the file you wrote is not the HTML the browser ends up with, and the validator only sees what you give it. Paste the final rendered source, or validate the live address, and fix the template that produced the bad markup rather than the output.
Frequently asked questions
- Why does my page look fine in the browser if the HTML has errors?
- Browsers parse HTML permissively. The HTML Standard defines how to recover from malformed markup, so most mistakes still render. The catch is that the browser's repair is not always the structure you intended, and different mistakes can produce layouts that only break in some situations.
- Do I need zero errors for a page to work?
- No. Pages with errors usually render. The W3C help page itself says a valid page is not necessarily a good page, and the Nu Html Checker describes itself as a checker, not a pass/fail certification. Fix errors because they point at real mistakes, such as unclosed elements, not to collect a green banner.
- Why does fixing one error remove many others?
- Errors cascade. One unclosed element or missing quote changes how the parser reads everything after it, so the checker reports follow-on problems. The W3C help page advises fixing the first few errors and then checking again.
- Can I check HTML offline?
- Yes. The Nu Html Checker is available as vnu.jar, which needs Java 17 or later, as an npm package (vnu-jar), through Homebrew, and as a Docker image. You point it at files or a folder instead of pasting markup into a web page.