onlinetools.dev

HTML Formatter & Minifier

Beautify messy HTML or minify it for production

Runs locally
loading…
About this tool

Beautify HTML that came out of a bundler, a scraper or a WYSIWYG editor: elements are indented to your chosen width, attributes stay on their line, and pre/textarea contents are left byte-for-byte intact. The minify mode strips comments and collapses the whitespace between tags — typically a 10–25% size cut on handwritten pages.

Minification here is deliberately conservative: inline scripts and styles are protected, conditional comments survive, and single spaces between inline elements are preserved so "click <a>here</a> now" does not fuse into "clickherenow". You get a safe minify, not a maximally aggressive one.

Both operations run locally in your browser — unpublished pages and internal admin markup never leave your machine.

Frequently asked questions

Will minifying break my inline JavaScript or CSS?
No — <script>, <style>, <pre> and <textarea> blocks are excluded from whitespace collapsing entirely. Only markup between tags is touched. To compress the scripts themselves, run them through the JavaScript minifier separately.
Why is whitespace between tags safe to remove?
Mostly it is: whitespace between block-level elements has no visual effect. Between inline elements it does, which is why the minifier collapses runs to a single space rather than deleting them. Layouts that depend on inline-block whitespace hacks are the rare exception worth eyeballing.
Does the formatter fix invalid HTML?
It formats what you give it without validating against the HTML spec — unclosed tags stay unclosed. Browsers are forgiving of tag soup, so formatting still helps you see the structure well enough to spot the problem.
What indent width should I use?
2 spaces is the prevailing convention in web codebases and what most framework style guides default to. Pick 4 if your team standardized on it — the choice is cosmetic.
Related tools