HTML Formatter

Beautify messy HTML into clean, indented markup, or minify it for production with the size saving shown. Nothing leaves your browser.

Input
0 B
Output
0 B
Change
0%

Beautify for reading, minify for shipping

Hand-written HTML drifts into a mess: mixed indentation, tags run together, stray blank lines. Beautify re-flows it into tidy, consistently indented markup with one element per line, so you can actually read and edit it. Choose two or four spaces, set an optional line wrap length, and keep or discard your existing line breaks.

When it is time to ship, Minify goes the other way. It collapses the whitespace between tags, trims long runs of spaces, and removes ordinary comments, so the file downloads faster. The exact byte count and percentage change appear above every time.

Whitespace-safe minification

A careless minifier corrupts your page by flattening whitespace that actually matters. This one does not. Before collapsing anything, it lifts out the contents of pre, textarea, script and style elements, minifies the rest, then puts them back byte for byte. A code sample inside a pre keeps its exact indentation, and inline scripts and styles are left intact.

It also respects conditional comments. Ordinary comments are stripped, but the legacy Internet Explorer conditional blocks are preserved because removing them could change how a page renders in those browsers.

Pitfalls to watch for

Minifying does not merge or remove attributes, and it will not touch inline event handlers, so your markup keeps working. Note that collapsing whitespace between inline elements such as span or a can very occasionally change the visible spacing on a page; if a layout depends on a single space between two inline tags, double-check it after minifying.

Cleaning up a whole front end? Reach for the CSS minifier, the JavaScript minifier and the JSON formatter too.

Frequently asked questions

What is the difference between beautifying and minifying HTML?
Beautifying re-indents your markup with consistent spacing and one element per line so it is easy to read and edit. Minifying does the opposite: it collapses the whitespace between tags and strips comments to make the file as small as possible for production. Both keep the rendered page identical.
Will minifying break my pre or textarea content?
No. This tool protects the contents of pre, textarea, script and style elements before collapsing whitespace, then restores them exactly. So the significant spacing inside a code block or preformatted text is never touched.
Does it remove HTML comments?
Minify removes normal comments, since the browser ignores them anyway. It deliberately keeps conditional comments (the old Internet Explorer if blocks) because those can still affect rendering. Beautify leaves all comments in place.
Is my HTML sent to a server?
No. All formatting happens in your browser with JavaScript, so nothing you paste is uploaded. It is safe to use with private templates and unreleased markup.