HTML Formatter

Beautify or minify HTML.

The HTML Formatter re-indents messy or minified HTML so the structure is readable, or squeezes readable HTML down by removing comments and indentation. Pick 2 spaces, 4 spaces or a tab, and the output updates as you type.

What does an HTML formatter do?

HTML ignores most whitespace between tags, so the same page can be written on one line or spread across hundreds of indented lines and the browser will build the same document tree. Beautifying adds line breaks and indentation that reflect nesting, which makes missing closing tags, wrongly nested elements and deeply buried attributes much easier to spot. Minifying goes the other way and removes characters that do not change how the page renders, such as comments and indentation, to reduce the size of what is sent over the network. Whitespace is not always free to remove, though. Inside pre and textarea it is part of the content, and between inline elements a single space can separate two words. This tool beautifies with the js-beautify library, and its minifier is deliberately conservative for that reason.

How to use HTML Formatter

  1. Paste your HTML Put the markup in the HTML box on the left. Empty input produces no output.
  2. Pick an operation Choose Beautify to indent, or Minify to strip comments and indentation.
  3. Set the indent With Beautify, choose 2 spaces, 4 spaces or Tab in the Indent selector. The output re-formats immediately.
  4. Copy or download Use the buttons on the Formatted HTML pane to copy the text or save it as formatted.html.

Frequently asked questions

Does minifying change how my page renders?

It is designed not to. It removes comments and indentation, collapses whitespace runs, and trims spaces around block-level tags. Content inside pre, textarea, script and style is untouched. Still, test the result on pages that depend on whitespace between inline elements.

Does it minify inline CSS and JavaScript?

No. style and script blocks are preserved exactly as written. Use the JavaScript Formatter for script content.

Which library does the beautifier use?

js-beautify, the same engine used by many editors. This tool sets it to not wrap long lines and to keep at most one blank line.

Can it fix broken HTML?

No. It formats the text it is given and does not validate or repair markup. Unclosed tags remain unclosed.

Is my HTML sent anywhere?

No. The formatting runs in the page and your input is not sent to a server.

Is there a size limit?

Yes, 2,000,000 characters per run.