HTML Formatter & Minifier

Turn tangled HTML into neatly indented code, or squeeze it down to the smallest file for production.

  • Processed on your device
  • Instant, no queue
  • Free, no sign-up
Advertisement
Your HTML
Beautified

Advertisement

How to use HTML Formatter

  1. Paste HTML on the left, open a file, or try the Messy example.
  2. Choose Beautify and pick the indent size and how to handle long attribute lists, or choose Minify to remove whitespace and comments.
  3. Copy the result or download it as an .html file. Use ⇄ to keep working on the output.

About this tool

HTML copied from a CMS, an email builder or the browser's developer tools often arrives as one long line or with random indentation. Beautifying puts every block element on its own line and indents children, so you can see at a glance where each section starts and ends and spot misplaced tags.

Inline elements such as <a>, <b> and <span> stay inside their sentence, so text still reads naturally, and short elements like <li>Item</li> stay on one line. Content inside <pre> and <textarea> is kept exactly as written, because whitespace there is visible on the page. CSS and JavaScript blocks are re-indented to match their surroundings.

Minify does the opposite: it collapses whitespace, removes comments (except old Internet Explorer conditional comments) and compacts CSS inside <style> tags, which reduces download size for production pages.

Questions and answers

Will formatting change how my page looks?

Beautifying only changes whitespace between block elements, which browsers ignore. Whitespace inside text is collapsed to single spaces, which is how browsers display it anyway. pre and textarea content is never touched.

How much smaller does minifying make HTML?

Typically 10 to 25 percent, more for heavily indented or commented files. Servers that use gzip or Brotli compress further, so the real-world gain is smaller but still worthwhile.

Does it minify JavaScript too?

It removes blank lines and indentation from script blocks but does not rename variables or rewrite code, because that needs a full JavaScript parser. Use a dedicated tool like Terser for that.

Can it fix broken HTML?

It formats whatever it is given, but it does not repair mistakes. Run your code through the HTML Checker first to find unclosed or mismatched tags.

Advertisement