HTML Validator
Paste HTML, a whole page or a part of one. See every error with its line and a fix. Nothing leaves your browser.
- 0
- Elements
- 0
- Advice
- 0
- Errors
On this page
About HTML Validator
Updated
What is an HTML Validator?
An HTML validator, or HTML checker, compares your markup with the rules of the HTML standard. It finds tags that are not closed, elements in places they may not go, repeated ids and attributes, obsolete tags, and images with no alt text. Browsers repair these mistakes without a word, each in its own way. A validator shows them, so the page works the same everywhere.
How to use this tool
Paste your HTML, open a file, or drop one on the editor. The tool checks it when you stop typing. A whole page (with <html>, <head> or a doctype) is checked as a page: it needs a doctype, a <title> and a language. A part of a page, such as a component or a template, is checked without those.
The Result pane lists each error with its line and column, says what is wrong in plain words, and says how to fix it. The editor marks the error you pick, the first one at the start. Click an error in the list to go to it, or use Next and Previous on its card. When one mistake causes others, such as an unclosed <b> that the parser carries into the next elements, you see one error, with the count of follow-on errors it causes.
Errors and advice
Errors break the HTML standard. Advice does not: it points at things that make a page harder to use, mostly for people with a screen reader or a keyboard. A field with no label, a link with no text, a heading that skips from <h1> to <h3>, a page with no language, or an old attribute such as bgcolor that CSS now does. Advice shows with a triangle, in the list and in Notes. Turn it off in Options to see the errors alone.
Outline
The Outline view shows the headings of the page as a tree, indented by level, also when the page has errors. A heading that skips a level is marked. Screen reader users move through a page by its headings, so the outline is the table of contents they hear. Click a heading to go to it in the editor.
Fix and Format
Fix repairs only what has one safe answer. It closes an unclosed tag before the end of the element that holds it, deletes a repeated attribute (browsers use the first one), and changes </br> to <br>. It adds <!DOCTYPE html> to a page with none. It also moves a </body> that comes too early, adds a missing ; to a character reference such as ©, and writes < or & for a raw < or &. Fix does not add alt text or a language: only you know what an image shows and which language the page is in. Undo takes back Fix and Format.
Format indents the HTML with 2 spaces, 4 spaces or tabs. For more format options, use the HTML Formatter. Checking XML, SVG or a sitemap? Use the XML Validator. For an RSS or podcast feed, use the RSS Feed Validator.
Common HTML errors
An element that is never closed
A tag such as <b>, <span> or <div> needs its end tag. Without it, everything after it counts as inside it. The page often still looks right, until a style or a script reads the structure.
<p>Meet the people <b>behind the shop.</p><p>Meet the people <b>behind the shop.</b></p>A block inside a paragraph
A <p> holds text and inline elements only. When the parser meets a <div>, a list or a table inside it, it closes the paragraph early. The later </p> then has nothing to close.
<p>Our route:
<div class="map">...</div>
</p><p>Our route:</p>
<div class="map">...</div>Something other than li in a list
A <ul> or <ol> holds only <li> items (and scripts and templates). Put the content inside an item.
<ul>
<div class="person">Anna, founder</div>
</ul><ul>
<li class="person">Anna, founder</li>
</ul>The same id twice
An id must be unique on the page. With two, a link to #team, a <label for> and getElementById all find only the first. Use a class for things that repeat.
<div id="team">...</div>
<div id="team">...</div><div id="team">...</div>
<div id="team-photos">...</div>An image with no alt
Every <img> needs an alt. Screen readers read it out, and browsers show it when the image does not load. For an image that is only decoration, write alt="" so screen readers skip it.
<img src="/img/anna.jpg"><img src="/img/anna.jpg" alt="Anna in the workshop, fixing a wheel">Obsolete tags and attributes
<center>, <font>, bgcolor and align come from HTML 4, when HTML did the layout. Browsers still draw them, but they are not part of HTML today. Use CSS. An old element such as <center> or <font> is an error. An old attribute such as bgcolor, align, width on a table or frameborder is advice, because HTML email still needs them: some mail programs read little CSS.
<center><font color="#777">Questions? Reply to this mail.</font></center><p style="text-align: center; color: #777">Questions? Reply to this mail.</p>This tool and the W3C validator
The W3C Nu HTML Checker is the reference, and this tool checks the same standard. We ran both on the same pages. On a test page with six mistakes, W3C gave 11 errors and 1 warning, because one unclosed <b> gave seven of the errors. This tool gave six, with the follow-on count on the first. We also ran 24 real pages from public GitHub projects through both. On 19 of 24, both found the same errors. On the others, W3C also checked CSS and a URL, counted skipped headings as errors (here they are advice), and flagged one ARIA role this tool lets pass.
There are three differences. W3C uploads your HTML to its server; this tool runs in your browser. W3C also checks the CSS in <style> tags, the values of ARIA roles and states, and attribute names it does not know; this tool does not. And this tool keeps accessibility advice apart, where W3C gives a few of those points as warnings and leaves out the rest.
Other HTML resources
- HTML Living StandardThe HTML standard from WHATWG: every element, where it may go, and its attributes.
- W3C Nu HTML CheckerThe W3C's own HTML checker, for a second opinion.
- MDN: HTML elements referenceEach element with its permitted content and parents, in plain words.
- How to Meet WCAG (Quick Reference)The accessibility rules behind the advice in Notes.
- html-validateThe open source HTML checker this tool runs in your browser.
- MDN: Quirks mode and standards modeWhat a missing doctype does to your layout.
HTML Validator FAQ
How do I validate my HTML?
Paste the HTML in the editor, open an .html file, or drop one on it. The tool checks it when you stop typing and lists every error at once, each with its line, column and a sentence on how to fix it. The editor marks the error you pick, the first one at the start. Click Fix to repair the safe ones, such as an unclosed tag or a repeated attribute. HTML with no errors gets the words Valid HTML.
What is a validator in HTML?
An HTML validator reads your HTML the way a browser does and compares it with the rules of the HTML standard: which elements exist, which elements may go inside which, which attributes they take, and which values those attributes allow. A browser quietly repairs broken HTML, each in its own way. A validator shows you what it had to repair, so the page looks and works the same in every browser.
What is the best HTML validator tool?
The reference is the W3C Nu HTML Checker at validator.w3.org/nu, made by the people who write the standard. Its messages are exact but terse, it sends your HTML to its server, and one broken tag can give a dozen errors. This tool checks the same rules in your browser, groups the follow-on errors under their cause, gives a fix for each error, and keeps accessibility advice apart from the real errors. For a final check before a launch, run both.
How can I test my HTML code?
Validate it here first, so the markup is right. Then open the page in two or three browsers and at phone width. For accessibility, read the advice in Notes, and use the keyboard alone to reach every link and field. For pages you change often, run a checker such as html-validate in your build, which uses the same rules as this page.
Is this the same as the W3C validator?
It checks the same HTML standard. On 19 of 24 real pages we tested, both found the same errors, and this tool often needed fewer lines to say them. It does not check the CSS inside <style> tags, which W3C also does. It gives advice that W3C does not, such as a field without a label. W3C counts a heading that skips a level as an error. Here it is advice, because the HTML still works. Advice never makes the HTML invalid.
How do I check a live web page?
Open the page in your browser and press Ctrl U (Cmd Option U on a Mac) to see its source. Select all, copy, and paste it here. This checks the HTML the server sent. To check the HTML after scripts changed it, open the developer tools, right-click the <html> element and choose Copy, then Copy outerHTML.
Can I check a whole website or a URL?
Not here. This tool checks one page at a time, from the HTML you paste or open. It does not get pages from an address, because nothing leaves your browser. To check one live page, copy its source as in the answer above. To check a whole site, run html-validate over your pages in your build. The W3C checker also takes one address at a time.
Is my HTML uploaded?
No. The check runs in your browser with html-validate, an open source HTML checker. Your HTML stays on your computer. A few seconds after the page has loaded, the checker is in your browser, and you can go offline and still validate.
Why do some checkers say my valid HTML is broken?
Some online checkers read HTML with an XML parser. XML is strict where HTML is not: HTML may leave out </p> and </li>, write <br> with no slash, and put < inside a script. An XML parser reports all of that as errors. This tool reads HTML with the HTML rules, so valid HTML passes.