How to Validate HTML and Fix the Most Common Validator Errors

Why browsers hide broken HTML, how to validate markup by URL or pasted code, and how to read and fix the errors and warnings the W3C validator reports most.

Updated September 29, 2026 5 min read

Use the free HTML ValidatorValidate HTML by URL or pasted code with the W3C checker, errors by line

The page looks perfect in your browser, yet a CSS rule refuses to apply, a screen reader announces the wrong structure, an email template falls apart in one client, or a search tool cannot find your meta description. Very often the cause is invalid HTML that the browser quietly repaired for you, in a way you did not expect.

This guide explains why browsers tolerate broken markup, what a validator checks, how to validate a page or a snippet, and how to read and fix the errors you are most likely to see.

Why browsers hide HTML mistakes

HTML parsers are designed to never give up. The HTML standard defines exactly how a browser must recover from every kind of error: unclosed tags are closed, misplaced elements are moved, and stray end tags are ignored. That is good for users, but it means:

  • Your mistakes are invisible until something relies on the structure you meant.
  • Different tools recover differently. Browsers follow the standard's recovery rules, but email clients, older parsers, crawlers and scripts may not.
  • A <div> closed in the wrong place can silently move a whole section into a different container, breaking layouts and CSS selectors.

A validator reads your markup strictly and tells you where it departs from the specification, so you fix the source instead of relying on repair.

What a validator checks

The W3C's Nu HTML Checker, the engine behind validator.w3.org, checks your document against the HTML standard. Messages come in three types:

Type Meaning Example
Error Breaks the specification Stray end tag </div>; element not allowed here
Warning Allowed, but probably a mistake or unnecessary Redundant type attribute on <script>
Info Informational notes Details about the document or parser

It checks HTML structure and attributes, not visual design, accessibility in full, or CSS stylesheets.

Validate HTML by URL or pasted code

The HTML Validator sends your markup to the W3C Nu checker and shows the results in a filterable list.

  1. Choose Paste HTML to check code, or Validate URL to check a live page.
  2. Paste your markup into HTML source (or click Load sample to see how results look), or enter the address in Page URL.
  3. Press Validate HTML.
  4. Use the All, Errors, Warnings and Info filters to focus the list. Each message shows the line and column, the validator's explanation and an extract of the source with the problem highlighted.
  5. Fix the issues in your source, validate again, and click Download report to save a plain-text copy for your team.

Paste mode is best for snippets, templates, email HTML and pages that are not online yet. URL mode is best for live pages, because it checks exactly what the server sends, including markup added by the CMS and plugins. Note that pasted code is sent to the W3C service, so avoid pasting confidential content.

Fixing the most common errors

Stray end tag

Error: Stray end tag "div".

There is a closing tag with no matching opening tag, usually one </div> too many. Tidy the indentation with the HTML Formatter, then count opening and closing tags around the reported line. Often the real mistake is a few lines earlier.

Unclosed elements

Error: End tag "section" seen, but there were open elements.
Error: Unclosed element "div".

An element was opened and never closed. Fix the first error in the list first; one missing tag can cause a cascade of later messages that disappear once it is fixed.

Element not allowed as child

Error: Element "div" not allowed as child of element "ul" in this context.

Some elements have strict content rules. A <ul> may only contain <li> (and script-supporting elements); a <p> cannot contain block elements such as <div>; interactive elements such as <a> cannot contain other interactive elements like <button>.

Duplicate ID

Error: Duplicate ID "signup".

IDs must be unique in a document. Duplicates break label for, in-page links, ARIA references and JavaScript lookups. They often come from a component included twice.

Missing alt attribute

Error: An "img" element must have an "alt" attribute...

Add a meaningful alt for informative images and alt="" for decorative ones.

Obsolete elements and attributes

Messages about <center>, <font>, align or bgcolor mean the markup uses presentational features removed from HTML. Replace them with CSS.

Bad attribute values

Invalid values, such as a width with "px" in it (width="300px" instead of width="300"), or an unescaped & in a URL, produce errors that are quick to fix once found.

Other ways to validate

  • validator.w3.org directly: the same checker, with file upload as an additional input method.
  • The vnu.jar command-line checker: the W3C publishes the Nu checker as a Java program you can run locally or in CI, which is ideal for validating many files or private code without sending it anywhere.
  • Editor linters and extensions: catch many mistakes as you type, though they are usually less strict than the Nu checker.
  • Browser DevTools: the Elements panel shows the repaired DOM. Comparing it with your source is a quick way to see what the browser changed.

Validation and SEO

Google does not rank pages by validation, and most large sites have some validator errors. What matters is severity. Errors in the <head>, such as a stray element that makes the parser close the head early, can push your title, meta description or canonical into the body where they may be ignored. Check those first, then review the page's tags with the Meta Tag Analyzer. Broader technical checks are in the Website SEO Audit.

Tips for a clean workflow

  • Fix errors top-down. Early errors cause later ones.
  • Validate templates, not every page. Most errors come from a shared header, footer or component.
  • Re-validate after minifying. If you compress markup with the HTML Minifier, validate the output too; aggressive settings occasionally remove something needed.
  • Accept some warnings. Warnings are advice. Fix those that point to real mistakes and ignore purely stylistic ones.

Frequently asked questions

Does invalid HTML affect SEO?

Not directly, and minor errors are common on well-ranking sites. Severe structural errors, especially in the <head>, can stop search engines reading titles and meta tags, so fix those.

Why does URL validation fail for my site?

The W3C server must fetch the page. Localhost, intranet sites, pages behind a login and sites that block bots cannot be checked by URL; paste the HTML instead.

Why do I get dozens of errors from one mistake?

One unclosed or misplaced tag changes how everything after it is parsed. Fix the first error, validate again, and many of the rest usually disappear.

Can it validate CSS too?

This tool checks HTML only. Use the W3C CSS Validation Service for stylesheets.

Is my pasted code private?

It is sent to validator.w3.org, run by the World Wide Web Consortium, for checking. Do not paste secrets or confidential content; use the local vnu.jar checker for sensitive code.

Try it now: HTML Validator

Loading tool…