HTML Validator

Errors found—
Opening tags—
Status—

How HTML Validator is calculated: Walk the tags with a stack: push opening tags, pop on matching closers, report mismatches and unclosed tags, and flag any id used twice.

What is an HTML validator?

An HTML validator checks a piece of HTML for the structural errors that break a page: tags that are closed in the wrong order, tags that are never closed, and ids used twice. Paste the HTML in and you get a report naming each problem. The default HTML here has 5 opening tags and 2 errors — a mismatched closing tag and a duplicate id.

Browsers are forgiving, which is the problem. A browser will render broken HTML by guessing what you meant, so a page can look fine while its structure is wrong — and the guess differs between browsers, which is how a layout breaks in one browser and not another. Validating finds the errors the browser silently worked around.

This is a basic check, not the W3C validator. It checks tag matching and duplicate ids with a small tag-stack parser in your browser. It does not check attributes, nesting rules, or the full HTML specification — for a complete check of a whole page, use the W3C validator. This tool is for a quick check of a fragment before you paste it in.

How HTML validation works

The method is a stack. Read the tags from left to right: every opening tag goes on top of the stack, and every closing tag must match the tag on top. The default HTML starts with div, then p, then b — the stack holds div, p, b. The next tag is a closing p, but the top of the stack is b, so the validator reports a mismatch.

On a mismatch, the validator recovers by popping tags until it finds the one being closed. The closing p pops b and then p, leaving div on the stack, and the closing div then matches. Recovery lets one error stay one error, instead of cascading into a dozen false reports for the tags that follow.

Two more checks run alongside. Any tag left on the stack at the end of the document is reported as unclosed, because a page that never closes a div will swallow the tags after it. And every id attribute is recorded — the default HTML uses id "a" twice, which is an error, because an id must be unique in a document.

Void elements and self-closing tags, explained

Some HTML elements never have a closing tag. These are void elements: br, img, input, hr, meta, link, and a few others. The validator knows the list, so an img tag without a closer is not an error — it is correct HTML, and the tag never goes on the stack.

Self-closing tags end with /> — <br /> or <img src="x" /> — and are also not pushed on the stack. In HTML, the slash on a void element is optional, so <br> and <br /> are the same thing. On a non-void element, <div /> is not a self-closing div in HTML — it is an opening div, and the validator treats it as one.

Comments and the doctype are skipped. An HTML comment can contain anything, including text that looks like a tag, and the validator ignores it. The doctype line at the top of a document is not a tag either, so it is skipped too.

Void elements are the tags that never have a closing tag, and the validator knows them by name. An img, a br, an input, and a meta tag are all void, which means they cannot contain anything and a closing tag after them is an error. The confusion comes from self-closing syntax: writing a slash before the closing angle bracket, such as a br with a slash, is allowed and harmless, but writing a separate closing tag, such as a closing br, is not. The validator treats the slash form as void and the closing-tag form as a mistake, which matches how browsers read the page.

A worked example: a broken fragment

Take the default HTML: a div containing a p containing a b, closed with /p then /div, followed by two spans that both carry id "a". That is 5 opening tags. The validator reports 2 errors: the closing p arrives while b is still open, and the id "a" is used twice.

Fix the first error by closing the b before the p — <div><p>Hello <b>world</b></p></div> — and the mismatch disappears. Fix the second by giving the spans different ids, such as "a" and "b", and the duplicate disappears. With both fixed, the report reads "Valid HTML: 5 tags, all matched, no duplicate ids."

Try an unclosed tag to see the third check: delete the closing div and the validator reports an unclosed div at the end of the document. An unclosed div is the error that swallows the rest of a page, because everything after it becomes part of that div — which is why the validator flags it even when the page looks fine.

Who uses an HTML validator, and why

Frontend developers are the main users. A template, a component, or a pasted fragment needs checking before it goes into a page, and a validator finds the mismatched tag in seconds. It is the fastest way to answer "why does this layout break in one browser?"

Email developers are the second group. HTML emails are built from fragments, and a mismatched tag in an email template breaks the layout in some mail clients and not others. Validating the fragment before sending saves a broken campaign.

Bloggers and content editors are a third group. A post with a pasted HTML snippet — a table, an embed, a styled block — can break the page around it when a tag is left open. A Markdown to HTML converter produces HTML from Markdown, and this validator checks the result.

Email developers are a third group. An email is built from HTML tables and inline styles, and the markup is often assembled by a template that can drop a closing tag without anyone noticing. The validator is the check before the send: paste the email's HTML, and the errors show whether the structure is sound. A broken table in an email renders badly in half the clients, and a validation pass before sending is cheaper than an apology after.

HTML validator vs other tools

A validator checks structure; other tools change format or measure text. The Markdown to HTML converter on this site produces HTML from Markdown, and this tool checks whether that HTML is well formed. Use the converter to make HTML, and the validator to check it.

The closest relative is the JSON validator, which checks whether JSON parses. Both tools answer the same question for different languages: is this text structurally sound? A JSON formatter tidies JSON, but HTML has no formatter here — the validator is the check, and your editor is the fix.

All three share the same design: paste, check, read the report, with the text never leaving the browser. If the HTML is valid here and still renders wrong, the problem is in the CSS or the content, not the tags.

A validator is not a linter, and the distinction matters when the goal is style rather than structure. A linter complains about naming, about deprecated attributes, and about patterns it dislikes, which is useful when the goal is a clean codebase. A validator only asks whether the tags are balanced and the ids are unique, which is useful when the goal is a page that parses. Use the validator to check the structure and a linter to check the style — the two tools answer different questions.

Common HTML mistakes

The first mistake is closing tags in the wrong order. Tags must close in the reverse of the order they opened — <div><p> must close as </p></div>, not </div></p>. The validator names the mismatch, and the fix is to swap the two closers.

Second: duplicate ids. An id must be unique in a document, because JavaScript and CSS use it to find one element. Two elements with id "a" mean a script that looks for "a" finds the first one and ignores the second. Use a class when several elements share a name, and keep ids unique.

Third: unclosed tags. A div that is never closed swallows everything after it, which breaks layouts in ways that look unrelated to the cause. The validator reports unclosed tags at the end of the document, so check the end of the report when a page's layout collapses.

Fourth: assuming the browser's rendering proves the HTML is valid. Browsers fix broken HTML silently, and different browsers fix it differently. A page that looks right in one browser can break in another, which is why validation matters even when the page looks fine.

A second mistake is assuming the validator checks whether the page looks right. It does not — it checks whether the tags are balanced and the ids are unique, which is structure, not design. A page can pass validation and still look broken, because the CSS is wrong or the content is missing, and a page can fail validation and still look fine, because browsers are forgiving about unclosed tags. Validation is a check on the markup, and the visual check is a separate job that needs a browser.

How to use this HTML validator

Paste your HTML into the box — the default has 5 opening tags and 2 errors to find. The report updates live: the error count, the tag count, and the status, with each problem named in the box below.

Fix the named problems in your editor, paste the HTML again, and watch the error count fall. When the report reads "Valid HTML", the fragment is structurally sound. To copy the report, use the Copy button next to the output box.

Everything runs in your browser. No sign-up, no account, no data sent anywhere — your HTML never leaves your device. It works offline once the page has loaded. Remember that this is a basic check of tag matching and ids, not the full W3C validator — for a complete check of a whole page, use the W3C validator.

Paste the HTML fragment, press validate, and read the error list from the top. Each error names the tag and the line, so an unclosed div is reported with the line where it opened, which is where the fix belongs. Fix the first error and validate again, because one unclosed tag can make every tag after it look wrong — the error list shrinks fast once the real problem is fixed. When the list is empty, the fragment is well formed, and the tag count underneath confirms how many tags were checked.

Frequently Asked Questions

No. This is a basic check of tag matching, unclosed tags, and duplicate ids, run in your browser. The W3C validator checks the full HTML specification, including attributes and nesting rules. Use this tool for a quick check of a fragment, and the W3C validator for a complete check of a whole page.

Browsers fix broken HTML silently by guessing what you meant, so a page can look fine while its structure is wrong. Different browsers guess differently, which is how a layout breaks in one browser and not another. Validation finds the errors the browser worked around.

No. Void elements — br, img, input, hr, meta, link, and a few others — never have a closing tag. The validator knows the list, so an img tag without a closer is correct HTML, not an error.

An id must be unique in a document, because JavaScript and CSS use it to find one element. Two elements with the same id mean a script finds the first one and ignores the second. Use a class when several elements share a name.

More free tools

More calculators and utilities from Sortrun — free, no sign-up.