Skip to content

HTML Beautifier & Minifier

Formats or minifies HTML, preserving inline elements and optionally collapsing whitespace.

Re-indents HTML so a page you have been handed is readable, or minifies it when the bytes matter. The tokeniser implements the WHATWG raw-text and RCDATA states, which is what stops a `</div>` inside a script string from being read as a tag and wrecking everything after it.

🔒 Runs entirely in your browserhtmlformatminifyweb
Mode
Indent
Attribute quotes
Line width

HTML in

Drop an .html file

Read in this tab only. Nothing is uploaded.

Formatted HTML

Elements

20

Text nodes

13

Comments

1

Max depth

5

How far it goes

  • · A hand-written tokeniser reads <script> and <style> as raw text and <textarea> and <title> as RCDATA, so a </div> inside a string is not mistaken for a tag.
  • · Nothing inside <pre> or <textarea> is changed by a single character; <script> and <style> are only re-indented line by line. The code inside them is not rewritten.
  • · Void elements like <br> and <img> and the elements whose closing tag may be omitted — <li> and <p> and <td> — are handled as the specification says. Missing closing tags are not inserted for you.
  • · Minification removes comments, whitespace and unnecessary quotes only. It does not drop optional closing tags or reorder attributes.
  • · Mismatched tags and duplicate attributes are reported with a line and column, and the document is still read as far as it can be — which is what a browser does.

The CSS inside can be cleaned up separately with CSS beautify & minify, and the scripts with JavaScript beautify & minify.

How to use it

  1. Paste a page or a fragment

    A whole document with a doctype, or a partial you copied out of a template. Both work; a fragment simply has no `html` element to indent inside.

  2. Set the layout

    Indent width, whether attributes get normalised to double quotes, the line width at which a long attribute list wraps, and whether the contents of `html`, `head` and `body` are indented — many hand-written pages leave those flush.

  3. Read the problem list

    Mismatched tags and duplicate attributes are listed with a line and column. The document is still formatted — the browser would render it too — but each entry is a thing worth fixing.

  4. Or minify for the wire

    Comments, whitespace and unnecessary attribute quotes come out. Conditional comments and `<!--!` comments are kept, and the before/after figures show what it bought.

Common questions

Is my `<pre>` block safe?

Yes. Nothing inside `<pre>` or `<textarea>` is changed by a single character, in either mode — whitespace there is content. `<script>` and `<style>` are re-indented line by line but their contents are never rewritten.

Does it add the closing tags I left out?

No. It understands them — `<li>`, `<p>` and `<td>` close implicitly, and void elements like `<br>` and `<img>` never had a closing tag — so the tree is built correctly. But writing tags you did not is an edit, not a format.

Can it format a template file — Jinja, ERB, Handlebars?

Only as far as the template syntax happens to look like text. `{% if %}` blocks are not understood as structure, so the indentation inside them will be wrong wherever a tag opens in one branch and closes in another. Format the rendered output instead.

Will minifying change how the page looks?

Whitespace between inline elements is significant in HTML, and collapsing it is the one setting here that can move a pixel — `<span>a</span> <span>b</span>` is not the same as the two spans touching. Turn Collapse whitespace off if your layout depends on it.

Feed it from

Next

These accept what this tool produces, so the result can go straight in.