HTML Formatter and Minifier

Beautify messy HTML with proper indentation, or minify it.

🔒 Runs entirely in your browser. Nothing you enter is uploaded or stored.

What is the HTML Formatter?

An HTML formatter (or HTML beautifier) takes HTML that is crammed onto one line, copied from a page source or badly indented, and rewrites it with one element per line and consistent indentation. Short elements that only contain text and inline tags stay on one line, so the result is easy to read rather than stretched out.

The Minify option does the opposite: it removes comments and unnecessary whitespace to make the HTML smaller. The content of <pre>, <textarea>, <script> and <style> is never changed, so code samples and inline scripts keep working.

How to use the HTML Formatter

  1. Paste your HTML into the box.
  2. Click Format to indent it, or Minify to compress it.
  3. Choose 2 spaces, 4 spaces or tabs for indentation.
  4. Copy or download the result.

Frequently asked questions

Does the formatter fix broken HTML?

It parses your HTML the way a browser does, so unclosed tags are closed and invalid nesting is repaired in the output. Check the result if your input was badly broken, because the browser's repair may differ from what you intended.

Is minified HTML safe for production?

Yes for normal pages. Whitespace between inline elements is kept as a single space so text does not run together. Comments are removed, including conditional comments for old Internet Explorer.

Why did my output gain <head> and <body> tags?

When you paste a full document (with a doctype or an html tag), it is parsed as a complete page, and HTML always has a head and body. Paste a fragment instead if you only want those elements formatted.