Web & CSS

HTML Formatter, Minifier & Validator

Paste HTML to beautify it, minify it, or check it for unclosed and mismatched tags. Built on a real tag-aware parser - script and style content is never mistaken for markup.

Ready.

What it does

Beautify reindents markup with one element per line and consistent nesting. Minify strips comments and collapses non-essential whitespace to shrink the file. Validate checks tag structure - unclosed tags, mismatched closing tags, duplicate attributes and a few other common mistakes - and reports each with a line and column.

Safe by design

  • A real tag-aware parser reads the markup first: <script> and <style> content is always treated as raw text, never as tags, so if (a < b) inside a script block is never misread as a tag.
  • Text content, attribute values and entities (&amp;, &copy;, and so on) are kept exactly as written - never decoded or re-encoded.
  • Content inside <pre>, <textarea>, <script> and <style> is never reformatted or reindented, since whitespace there is either significant to rendering or could be part of a multi-line string.
  • The optional preview renders in a sandboxed <iframe> with scripting disabled - pasted <script> tags are never executed, and the frame cannot read cookies, storage or anything else from this page.

Good to know

This checks well-formedness (matching tags, no duplicate attributes) with a hand-built parser chosen so every case here could be tested directly - it does not implement a browser's full HTML5 parsing algorithm (such as automatically closing a <p> when another block element starts, or the full adoption-agency algorithm for badly mismatched tags), and it is not an HTML validator against the WHATWG/W3C specification (it won't catch things like an <img> missing an alt attribute). When tags are mismatched, Format and Minify recover the same way Validate reports it: an unmatched closing tag is dropped, and a mismatched one closes back up to its nearest matching ancestor.

Example

This one-line page:

<!doctype html><html><head><title>Demo</title></head><body><main><h1>Hello</h1><p>One <strong>two</strong> three</p><ul><li>A</li><li>B</li></ul></main></body></html>

is beautified into a readable tree. Inline elements such as <strong> stay inside their line, so text is not split apart:

<!doctype html>
<html>
  <head>
    <title>Demo</title>
  </head>
  <body>
    <main>
      <h1>Hello</h1>
      <p>One <strong>two</strong> three</p>
      <ul>
        <li>A</li>
        <li>B</li>
      </ul>
    </main>
  </body>
</html>

Validate: three kinds of problems

In Validate mode the tool lists problems with the line and column. For this input:

<div><p>One</div>
<img src="a.png" src="b.png">
<span>x

it reports 1 error and 2 warnings:

  • Warning (line 1, column 6): <p> was never explicitly closed, because the closing </div> closed it implicitly.
  • Warning (line 2): duplicate attribute src on <img>.
  • Error (line 3): <span> was opened here and is never closed. The result is “Not valid”.

Frequently asked questions

Does the formatter change how the page looks?

No. It changes only whitespace between tags. The content of pre and textarea elements is kept exactly as you wrote it, because whitespace is part of what they show.

Is this the same as the W3C validator?

No. It finds common structural mistakes such as unclosed tags and duplicate attributes. For a full conformance check, use the official validator.

How do I convert Markdown to HTML?

Use the Markdown to HTML Converter.

Is my HTML uploaded?

No. It is processed in your browser.

Privacy

This tool runs entirely in your browser, including for large files handled by a background Web Worker. What you enter is processed on your device and is not sent to a server.

Share this tool

Your data is not included in this link.