HTML Formatter and Minifier Online

This html beautifier minifier cleans up markup either way. Paste HTML to beautify it with neat indents and line breaks, or minify it to cut spaces and comments for faster loading. Copy or download the result.

HTML Formatter & Minifier

Beautify or minify HTML code.

Everything runs in your browser. Nothing you enter or upload is sent to a server.

How to use the HTML Formatter & Minifier

  1. Paste your HTML.
  2. Press Format to beautify it, or Minify to compress it.
  3. Check the size change in the message.
  4. Copy or download the result.

How it works

Formatting uses js-beautify, the open-source library behind many code editors. Minifying removes comments (except conditional comments), collapses runs of whitespace and removes spaces between tags, while leaving pre, textarea, script and style blocks untouched.

Example

Minifying "<div>\n <p>Hello world</p>\n <!-- note -->\n</div>" gives "<div><p>Hello world</p></div>".

Frequently asked questions

Does minifying break my page?

Rarely. Spaces between inline elements can matter, so check the result.

Is my code uploaded?

No. It is processed in your browser.

Can it format CSS or JS inside HTML?

The formatter indents embedded CSS and JavaScript too.

See also: JSON Formatter.

Format or minify HTML

How to use it

  1. Paste your HTML.
  2. Pick beautify or minify.
  3. Check the result.
  4. Copy or download.

More questions

Does it fix broken HTML?

It formats what you paste but does not rewrite bad markup.

Are inline scripts kept?

Yes. Inline scripts and styles stay in place.

Is my code uploaded?

No. Everything stays in your browser on your device.

Related tools: CSS Minifier and Beautifier, JavaScript Minifier and Beautifier, Markdown to HTML Converter.

Formatting adds bytes, minifying removes them

Paste your HTML and press Format to indent it with 2 or 4 spaces, or press Minify to compress it. The message under the buttons shows the size before and after. To preview your markup as you edit it, try the Online HTML Editor.

Worked example: a 132-byte snippet with a heading, a paragraph, a list and one comment formats to 8 lines and 155 B, and the message reads "Formatted: 132 B to 155 B (+17%)." Minifying the original with Remove comments ticked reads "Minified: 132 B to 118 B (-11%).", and with the box unticked the comment stays and the size stays at 132 B.

More answers

Why does Format make my file bigger?

Indenting adds spaces and line breaks. The 132-byte snippet grows to 155 bytes (+17%) when formatted with 2 spaces, which is fine for reading and editing but not for shipping.

Does Minify change the contents of pre or textarea tags?

No. The text inside pre, textarea, script and style tags is kept exactly as written, while the whitespace between other tags is collapsed.