Home/Developer Tools/HTML Formatter & Minifier
🏷

HTML Formatter & Minifier

FREE

Beautify or minify HTML without changing how it renders

Free · No sign-up required
Loading...

What the HTML formatter does

Two operations on HTML: beautify turns minified, machine-generated or copy-pasted markup into consistently indented code with one element per line, and minify strips comments and collapses whitespace for production. Formatting changes only whitespace between tags — never the tags, attributes or text content — so the page renders identically. It runs in your browser; markup from private sites is not uploaded.

Before and after

Before: <div class="card"><h2>Title</h2><p>Some <strong>bold</strong> text.</p><ul><li>One</li><li>Two</li></ul></div> After: <div class="card"> <h2>Title</h2> <p>Some <strong>bold</strong> text.</p> <ul> <li>One</li> <li>Two</li> </ul> </div>

Inline elements (strong, a, span, code) stay on the same line as their surrounding text, because breaking them would change rendered spacing. Block elements each get their own line and are indented by nesting depth.

Where whitespace matters in HTML

  • Inside <pre>, <textarea> and <script>, whitespace is content. The formatter leaves those blocks untouched.
  • Between inline elements, a line break is rendered as a space. That is why <a> tags on separate lines get a gap between them, and why the beautifier keeps inline runs together.
  • Between block elements, whitespace is ignored, so indenting divs and lis is safe.
  • The minifier removes whitespace only where it is safe, keeping single spaces between inline content.

Common uses

  • Reading the source of a page that shipped minified, or a template generated by a CMS or email builder.
  • Cleaning up HTML pasted from Word, Google Docs or a WYSIWYG editor before committing it.
  • Reformatting before a code review so the diff shows real changes, not indentation.
  • Producing a minified snippet for an email template, an embed code or an inline srcdoc.
  • Tidying HTML fragments for documentation and tutorials.

What minification saves

RemovedTypical saving
CommentsVaries — can be large in templated pages
Indentation and line breaks5–20% of raw size
Redundant whitespace inside tagsSmall
After gzip / brotli1–5% — compression already handles whitespace well

As with CSS, minifying HTML matters less than it used to because transport compression is universal. It is still useful for stripping comments that may contain internal notes, and for size-limited contexts such as email and embed snippets.

Frequently asked questions

Does it fix invalid HTML?

No. It formats what is there; unclosed tags stay unclosed. Run the result through the W3C validator or an editor's linter for correctness.

Will beautifying change how the page looks?

It should not — whitespace is only added between block elements and inside preserved blocks is left alone. If inline elements are formatted incorrectly by another tool, spacing can change; this tool keeps them inline.

Does it handle templates (Blade, Jinja, JSX)?

Template tags are treated as text, so the HTML around them is formatted and the tags are preserved. JSX with expressions may not indent ideally; use Prettier for JSX.

Can I choose 4-space indentation or tabs?

Not in this tool; output uses 2 spaces. Editors with Format Document, or Prettier, offer configurable styles.

Does minifying remove optional closing tags?

No. It only removes whitespace and comments, so the structure is unchanged. Aggressive minifiers like html-minifier can drop optional tags in a build step.

Is my HTML uploaded?

No. Formatting runs in your browser.

More tools in this category

📋
JSON Tools
View tree, format, validate and minify JSON
📄
YAML Beautifier & Validator
Format YAML and find the line that breaks it
📋
XML Tools
Beautify, validate and convert XML to JSON
🗃
SQL Formatter & Minifier
Lay out SQL clause by clause, or collapse it to one line
📝
Markdown Tools
Preview Markdown, convert to HTML and generate tables
🔑
JWT Encoder & Decoder
Decode a JWT's header and payload, or sign one with HS256