Format or minify HTML

Free online HTML formatter and minifier — paste a minified bundle and read it indented, or shave bytes off an email template before deploying. Auto-detect mode picks the right direction (compact one-line input → indented output, indented input → one-line output), or pick manually. Indent with 2 spaces, 4 spaces, or tabs. Void elements (br, hr, img, input, meta, link) can be self-closed XHTML-style or left bare HTML5-style. Content of <pre>, <script> and <style> is preserved verbatim — formatters that mangle these blocks break syntax-highlighted code samples on every blog. Comments can be optionally stripped from both directions.

How to use

1
Paste HTML

Direction is auto-detected by default.

2
Pick indent and options

2 spaces is the standard for most front-end style guides.

3
Read the output

Either prettified or minified version appears on the right.

4
Copy or download

One-click clipboard or save as .html.

Beautify or minify HTML in the browser — preserves <pre>, <script>, <style> content verbatim

Mode
Indent
Options
Input
Output

            
        
Don't know what to try?
400+ free tools — open a surprise
🎲 Surprise me

Features

Format and minify Auto-detect mode Three indent styles Preserves verbatim blocks Self-closing toggle Strip comments

Typical uses

  • Beautify a copy-pasted minified HTML file to inspect its structure.
  • Minify an HTML email template before deploying — shaves bytes off every send.
  • Convert HTML5 void elements to XHTML self-closing for an XML-strict pipeline.
  • Strip developer comments from a production HTML build.
  • Re-indent a hand-edited template to match team conventions.

Why this one

Many browser-based formatters mangle the contents of <pre> or <script> — copy a code snippet through one and your indentation is shot. This one recognises raw-text elements (script, style, pre, textarea) and leaves their content alone byte-for-byte. Everything else gets clean per-block indentation. No signup, no per-file quota.

Common questions

What is a "void element"?

An HTML element that has no closing tag and no content — br, hr, img, input, meta, link, source, track, area, base, col, embed, param, wbr. In HTML5 these can be written as <br> (preferred) or <br /> (XHTML legacy). Pick whichever your linter expects.

Does it modify content inside &lt;script&gt; or &lt;style&gt;?

No. Anything inside <script>, <style>, <pre>, and <textarea> is preserved byte-for-byte. Whitespace handling around those tags follows HTML5 raw-text element rules.

Why does my minified output still have spaces?

Minification collapses inter-tag whitespace but preserves at least one space where it is semantically meaningful (between inline elements like <span> or <a>) — removing those spaces visibly changes the rendered page. For aggressive whitespace stripping use a build-time minifier (html-minifier-terser, htmlnano) where you can tune the trade-off.

Will this fix unclosed tags?

No — the tool is purely a formatter. If you have unclosed <div>s the output will reflect the (broken) structure. Use a validator like the W3C Nu Validator for structural lint.

Does it handle templating syntax like @{{ ... }} or {% %}?

It tries to leave most templating tokens intact, but Blade ({{ }}), Twig ({% %}), Vue ({{ }}), etc. can still get spaced oddly. For templates with heavy interpolation, format the rendered HTML or use a templating-aware tool.

Mobile?

Yes — input and output stack on narrow screens.

💡 Want us to improve this tool just for you?

We can — and it's free! Just send us a quick message with your idea. If you'd like to discuss it in detail, leave your email and we'll get back to you. You can stay anonymous.

How do you rate this tool?

Thank you for your rating!
Want to share more? Leave a comment!
Thank you! Your comment will appear after moderation.
Published Updated