Every browser renders invalid HTML — they just render it differently. That inconsistency is the root cause of most cross-browser layout bugs, broken structured data, and misread meta tags. This guide covers the best tools to check HTML for errors, how to read validator output, the most common HTML mistakes and their fixes, and how to build HTML validation into your development workflow so errors never reach production.
Why HTML validation matters
Browsers do not reject invalid HTML — they have built-in error recovery that attempts to render malformed markup as best they can. The problem is that each browser's recovery algorithm is different. A missing closing tag that Chrome handles one way may render completely differently in Safari or Firefox, producing layout bugs that are notoriously difficult to diagnose and reproduce.
The four reasons to validate HTML
- Cross-browser consistency — valid HTML is the only guarantee that all browsers render your page identically
- SEO and crawlability — malformed markup causes crawlers to misread canonical tags, structured data, and meta descriptions
- Accessibility — screen readers depend on correct heading order, label associations, and ARIA attributes that invalid HTML can break
- Maintainability — valid markup is easier to style, script, and modify without unexpected side effects
What the HTML specification requires
The HTML5 specification defines a conformance model — a set of rules that valid HTML documents must follow. These rules cover element nesting, required attributes, deprecated elements, void element syntax, character encoding declarations, and dozens of other constraints. A validator checks your markup against these rules and reports every violation. Fixing the violations gives you markup that every spec-compliant parser handles identically.
Note
Types of HTML errors
Validators classify issues into two categories: errors and warnings. Understanding the distinction before you start fixing helps you prioritise correctly and avoid wasting time on issues that have no real-world impact.
Errors vs. warnings
| Issue type | Example | Impact | Priority |
|---|---|---|---|
| Unclosed tag | <div> without </div> | Nesting collapse, broken layout | Fix immediately |
| Invalid nesting | <p><div>…</div></p> | Browser auto-corrects inconsistently | Fix immediately |
| Deprecated element | <font>, <center>, <frame> | Removed from HTML5 spec | Fix when refactoring |
| Duplicate attribute | id="x" id="y" on same element | Second value silently ignored | Fix immediately |
| Missing required attr | <img> without alt | Accessibility failure | Fix immediately |
| Obsolete attribute | type="text/javascript" | Redundant but harmless in HTML5 | Low priority |
| Bad character encoding | & without ; in unquoted value | Parse ambiguity | Fix when noticed |
| Warning: ARIA misuse | role on wrong element | Screen reader confusion | Fix with accessibility pass |
Parse errors vs. conformance errors
A parse error means the HTML tokeniser encountered something it cannot process — like a bare `<` character in text content, or an attribute value missing its closing quote. A conformance error means the markup is syntactically parseable but violates a specification rule — like nesting a `<div>` inside a `<p>`. Both show up as errors in a validator, but parse errors are more urgent because they cause unpredictable tokenisation behaviour across different rendering engines.
Tip
How to check HTML for errors
There are four practical methods for checking HTML for errors, each suited to a different stage of development. Using them in combination gives you the most complete coverage.
Paste HTML into the online validator
The fastest method: open the HTML Validator, paste your markup — full document or snippet — and run the check. Results appear immediately with line numbers, element names, and a plain-English description of each issue. This works for checking templates, generated HTML, email markup, and any HTML you cannot easily view in a browser.
Use browser DevTools for live inspection
Open DevTools (F12 in Chrome or Edge, Cmd+Option+I on Mac) and inspect the Elements panel. The browser's rendered DOM shows how it interpreted your markup after error recovery — missing closing tags appear as auto-inserted elements, and malformed nesting shows up as rearranged tree nodes. The Console tab also logs some HTML parse errors directly. DevTools shows the post-recovery DOM, not your source, so use it alongside a validator rather than instead of one.
Run the W3C validator for standards compliance
The W3C Markup Validation Service at validator.w3.org is the authoritative reference validator for the HTML5 specification. It accepts a URL, file upload, or direct input. Use it for a definitive standards compliance check before major releases, or when a client or auditor requires W3C validation certification. For rapid iterative checking during development, a browser-based validator is faster.
Fix broken markup automatically with the HTML Broken Tag Fixer
If your HTML has a large number of unclosed tags or nesting errors — common in HTML generated by CMS exports, PDF-to-HTML converters, or legacy templates — the HTML Broken Tag Fixer automatically closes unclosed tags and corrects mismatched nesting. Use it to get a clean base, then re-validate to confirm the structural fixes are correct.
Re-validate until the error count is zero
After fixing errors, paste the corrected HTML back into the validator and run again. Some errors only become visible after fixing earlier ones — a single unclosed `<div>` near the top of a document can mask dozens of downstream nesting errors. Repeat the validate-fix-validate cycle until the result is clean.
HTML Validator
Check any HTML for unclosed tags, invalid nesting, deprecated elements, and HTML5 compliance — instant results with line numbers and plain-English error descriptions, no upload required.
Understanding validator output
Validator output looks intimidating on a page with many errors, but it follows a consistent structure. Understanding the anatomy of a single error message lets you work through a long list efficiently without reading each one in full detail.
Anatomy of a validator error message
Every error contains four pieces of information: the location (line number and column, e.g. `Line 47, Column 12`), the severity (Error or Warning), the element or attribute involved (`element "div"`, `attribute "align"`), and the rule violation description in plain English. The description is the most important part — it tells you exactly what the spec requires and what your markup provided instead.
Cascade errors and how to identify them
When a parser encounters an unclosed tag, it may misinterpret everything that follows, producing a cascade of secondary errors that are all caused by the single original mistake. If your validator output shows many errors on consecutive lines all involving the same parent element, look for an unclosed tag or incorrect nesting higher up in the file. Fix that one issue and re-validate — the cascade errors will likely disappear.
Warning
What "end tag for element which is not open" means
This error means the validator encountered a closing tag — like `</div>` — with no corresponding open tag at that nesting level. The most common cause is a mismatched open/close tag pair earlier in the document where the open tag was misspelled or accidentally deleted. Count the `<div>` and `</div>` occurrences in the affected region to find the mismatch.
Common HTML errors and how to fix them
These are the errors that appear most frequently in real-world HTML validation results. Each entry describes the error, shows why it occurs, and gives the direct fix.
Unclosed tags
An unclosed `<div>`, `<span>`, `<p>`, or `<li>` is the most common HTML error. Browsers close unclosed tags automatically, but each browser's auto-close algorithm is different. In block elements like `<div>`, an unclosed tag can absorb subsequent content into the wrong parent, breaking your CSS layout. The fix is straightforward: add the missing closing tag at the correct nesting level. The HTML Broken Tag Fixer handles this automatically for large documents with many unclosed tags.
Invalid nesting
HTML nesting rules are specific: `<p>` elements cannot contain block-level elements like `<div>`, `<ul>`, or `<table>`. `<li>` must be a direct child of `<ul>` or `<ol>`. `<td>` must be a direct child of `<tr>`. When you nest elements incorrectly, browsers fix the nesting themselves — sometimes by moving your element outside its intended parent, breaking the visual layout. The fix is to restructure the affected markup so every element is a valid child of its parent.
Missing required attributes
- `<img>` without `alt` — required by HTML5 and critical for screen readers; add descriptive alt text or `alt=""` for decorative images
- `<input>` without `type` — defaults to `text` but should be explicit for form semantics and mobile keyboard hints
- `<a>` without `href` — an anchor without href is technically valid but semantically meaningless; use `<button>` for click actions instead
- `<meta charset>` missing — required in HTML5; add `<meta charset="UTF-8">` as the first element inside `<head>`
- `<html lang>` missing — required for accessibility; specify the page language with `lang="en"` or the appropriate BCP 47 tag
Deprecated and obsolete elements
HTML5 removed `<font>`, `<center>`, `<strike>`, `<frame>`, `<frameset>`, and several presentational attributes like `align`, `bgcolor`, and `border` on most elements. Validators flag these as errors because they are not part of the HTML5 specification. Replace them with their CSS equivalents: `<center>` becomes `text-align: center`, `<font>` becomes inline styles or CSS classes, and `<frame>` becomes `<iframe>` or a CSS layout approach.
Duplicate IDs
Every `id` attribute value must be unique within a page. Duplicate IDs cause JavaScript `document.getElementById()` to return only the first matching element, CSS `:focus` behaviour to target the wrong element, and anchor links to scroll to the wrong location. Validators flag every duplicate ID as an error. Audit your HTML with the HTML Validator to find all duplicates, then make each ID value unique or convert the repeated `id` to a `class` if the value is used for styling rather than identification.
HTML validation in your workflow
Running a validator once at launch is better than nothing, but the highest-value approach is validating HTML continuously throughout development. The earlier an error is caught, the cheaper it is to fix.
During development: editor linting
VS Code's built-in HTML language server highlights unclosed tags and invalid nesting in real time as you type. For stricter checking, the `HTMLHint` extension applies configurable HTML rules on save. The `Prettier` formatter automatically closes self-closing void elements and normalises attribute quoting, which prevents a class of formatting-related errors before they reach a validator.
In CI/CD: automated validation on every commit
Add HTML validation to your CI pipeline using `html-validate` (npm) or the W3C validator's command-line interface. Run validation against your built output files on every pull request so errors are flagged before they merge. A failing validation check is a far better signal than discovering broken layout in production after release. Combined with the HTML Accessibility Quick Audit tool, you can catch both spec violations and accessibility errors in a single automated pass.
Before publishing: pre-launch validation sweep
Before every significant release, run your critical pages — home, key landing pages, checkout flow, blog posts — through the HTML Validator manually. This catches any errors introduced by template changes, CMS updates, or third-party embed code that your automated checks may have missed. Pair this with a CSS Validator check for complete front-end quality coverage.
HTML Accessibility Quick Audit
Audit HTML for missing alt attributes, unlabeled form controls, and heading order problems — catches accessibility errors that standard HTML validators do not report.
Beyond syntax: accessibility and SEO
A valid HTML document is a necessary foundation, but it is not sufficient for accessibility or SEO on its own. Once your markup passes the HTML validator, two additional checks add meaningfully more coverage.
Accessibility issues HTML validators miss
The HTML5 specification says nothing about keyboard focus order, contrast ratios, or ARIA landmark regions. A fully W3C-valid page can still fail WCAG 2.1 accessibility standards in multiple ways. The HTML Accessibility Quick Audit checks specifically for the most common accessibility violations in HTML markup: missing `alt` text on images, `<input>` elements without associated `<label>`, incorrect heading hierarchy, links without descriptive text, and buttons without accessible names. These are issues that affect real users with assistive technologies and that standard validators do not flag.
How HTML errors affect SEO
Search engine crawlers parse HTML to extract structured data, canonicals, meta descriptions, and content. Malformed HTML can cause crawlers to misread or skip these elements entirely. The most SEO-critical HTML errors are: unclosed tags that absorb `<title>` or `<meta>` elements into the wrong parent, broken JSON-LD `<script>` blocks caused by special characters that were not HTML-encoded, and duplicate canonical tags caused by template errors. Running the HTML Validator before publishing protects your structured data and metadata from these parsing failures.
Note
Using valid HTML helps ensure your page renders correctly and that search engines can accurately read and process your page content.
Key takeaways
- Browsers render invalid HTML through error recovery — but each browser's recovery algorithm differs, causing cross-browser layout bugs.
- Validator output distinguishes errors (spec violations to fix) from warnings (best-practice issues to review).
- Fix cascade errors by addressing the first error in the list and re-validating — one unclosed tag can generate dozens of downstream errors.
- Use the HTML Broken Tag Fixer to automatically repair large numbers of unclosed tags before manual validation.
- The most common HTML errors are unclosed tags, invalid nesting, missing required attributes, deprecated elements, and duplicate IDs.
- Run the HTML Accessibility Quick Audit after HTML validation to catch accessibility errors the spec validator misses.
- Add HTML validation to your CI/CD pipeline so errors are flagged on every pull request, not discovered after deployment.