How to Validate HTML: Errors, Warnings, and Best Practices
Find and fix HTML validation errors affecting SEO, accessibility, and rendering. Using validators and interpreting results.
Why Validation Matters
Valid HTML ensures consistent browser rendering, correct assistive technology interpretation, and proper search engine parsing. While browsers forgive invalid HTML with error recovery, corrections aren’t always what you intended. An unclosed div might shift layout. Missing alt makes images invisible to screen readers. Invalid nesting causes unpredictable cross-browser rendering. Use the HTML Formatter to fix formatting issues.
Common Validation Errors
Common real errors: missing alt on images, unclosed container elements such as <div>, duplicate IDs (which break getElementById, label associations and ARIA references), block elements inside inline ones (a <div> inside a <span>), obsolete elements such as <font> and <center>, and a missing doctype. Two things often listed as errors are not: </p> and </li> end tags are optional in HTML, and an <input> needs neither name (only to be submitted with a form) nor type (it defaults to text). A missing lang attribute is a warning, though it matters for screen readers and translation.
Using the W3C Validator
The W3C validator for HTML is the Nu Html Checker (validator.w3.org/nu, also available as the open-source vnu.jar). It reports errors, warnings and info messages. Fix errors first, starting with accessibility (missing alt text, labels, broken ARIA) and structure (unclosed containers, duplicate IDs).
Worked Example: What the Validator Actually Flags
We put each commonly cited "error" in a minimal page and ran it through the Nu Html Checker, vnu.jar 26.10.12 (script and results in our test folder, October 13, 2026):
| Markup | Result |
|---|---|
<p>One<p>Two and <li> without end tags | Nothing — valid |
<input> without name or type | Nothing — valid |
<html> without lang | Warning |
Unclosed <div> | Error |
Duplicate id | Error |
<img> without alt | Error |
<font> and <center> | Error (obsolete) |
<div> inside <span> | Error |
No <!DOCTYPE html> | Error |
Validation is about the HTML Standard's rules, not about style: leaving out optional end tags is fine, while the errors above can change how the page is parsed or what assistive technology announces.
Validation in Your Workflow
Integrate validation into development: add html-validate npm package to CI/CD, use VS Code HTML validation extension for real-time feedback, run Lighthouse audits before releases. For existing sites with many errors, prioritize: accessibility errors first (missing alt, form labels, broken ARIA), then structural (nesting, duplicate IDs), then warnings. Zero errors should be the standard; zero warnings is a bonus.
Frequently Asked Questions
Will invalid HTML hurt SEO?
Must I fix every warning?
Does valid HTML guarantee correct display?
- [1]Search Engine Journal (2020): John Mueller — W3C validation is not used in Search ↗
- [2]Nu Html Checker (W3C validator, vnu.jar) ↗
- [3]validator/validator on GitHub (vnu.jar source and releases) ↗
- [4]WHATWG HTML Standard: optional tags ↗
- [5]WHATWG HTML Standard: the input element (type defaults to text) ↗
- [6]html-validate (Node validator for CI) ↗