Skip to content
M2TOOLKIT

Developer · free tool

HTML Formatter & Beautifier

Clean up messy HTML with proper indentation, or minify it.

Use it as often as you like — it's free, with no sign-up and no limits.

  • Developer
  • Free
  • No sign-up
  • Runs in your browser
  • Updated
Output

Your code is formatted in the browser and never executed.

Everything you type is processed in your browser. Nothing you enter is sent to our servers or stored by us.

How to use the HTML Formatter

  1. Paste your HTML into the left box, or open a file.
  2. Adjust the options if you need to.
  3. Copy the formatted HTML or download it as a file.

What does this tool do?

Formatting uses the open-source js-beautify engine, loaded only on this page. Inline CSS and JavaScript inside the HTML are formatted too. Your code is only re-printed, never run.

What Minify removes, and when that matters

Minify deletes HTML comments, the whitespace between tags and any run of two or more spaces, which it turns into one. Conditional comments for old versions of Internet Explorer are kept. It is a plain text pass, not an HTML parser, so it also collapses spaces inside <pre> blocks and <textarea> content, and indented text inside <script> or <style> loses its layout. Do not minify snippets that contain those.

The saving on a short snippet is small. For a whole site, use the minifier in your build tool.

Related: CSS formatter · XML formatter · Markdown to HTML

What Beautify cannot fix

Beautify re-prints the code; it does not repair it. A missing closing tag stays missing, and the indentation will show you where the structure goes wrong, which is the quickest way to find it. Inline JavaScript and CSS are formatted along with the HTML.

The code is only formatted, never executed, so pasting someone else's page source is safe.

Why use it?

  • Read minified page source.
  • Tidy templates and emails.
  • Quick minification for small snippets.

Worked example: what Beautify and Minify each do to the same snippet

Starting from <div class="card"><h2>Title</h2><p>Some <b>bold</b> text.</p><ul><li>One</li><li>Two</li></ul></div>, Beautify puts each block element on its own line, indented 2 spaces, and ends the file with a newline. Minify takes the neat version back to a single line.

OptionEffect
Beautify, 2 or 4 spaces, or tabsBlock elements on separate lines, inner HTML indented
Blank lines in your inputUp to 2 in a row are kept
Long linesNever wrapped
MinifyRemoves comments, whitespace between tags and repeated spaces

Privacy

Everything you type is processed in your browser. Nothing you enter is sent to our servers or stored by us. There's no account to create and nothing to install.

Frequently asked questions

Can minifying HTML break my page?

Rarely, but whitespace between inline elements (like links or buttons side by side) can be visible, and removing it can change spacing slightly. Check the page after minifying; content inside <pre> tags should keep its spacing.

Is my HTML run or loaded when I format it?

No. The code is only re-printed as text. Scripts aren't executed and images or other resources aren't loaded.

Content last updated . See how M2Toolkit works.

Other tools people use alongside the html formatter.