HTML Formatter and Minifier

Beautify messy HTML with clean indentation or minify it to shrink the file size.

This tool runs entirely in your browser. Your markup is never uploaded anywhere.

How to use this tool

Pick a mode at the top. Choose Beautify to reformat compressed or tangled HTML into readable, indented markup, or choose Minify to strip the whitespace and comments and make the file smaller. Paste your HTML into the input box. If you are beautifying, set the indent size you prefer (two spaces, four spaces, or a tab). Click Format HTML, then use the copy button to grab the result. Everything happens locally, so even large or private templates stay on your machine.

How it works

Beautify: walk every <tag>, increase the indent after an opening tag, decrease it before a closing tag, place each tag on its own line. Minify: collapse runs of whitespace between tags to nothing, trim text nodes, and remove <!-- comments -->.

The beautifier scans the markup tag by tag. Self-closing tags (like <br> or <img>) and void elements do not change the indent level. A normal opening tag pushes the indent one step deeper for the lines that follow, and a closing tag pulls it back one step before the line is printed. The minifier does the opposite: it removes the spaces and line breaks that sit between tags, trims stray whitespace inside text, and deletes HTML comments so the browser downloads fewer bytes. Content inside <pre>, <script>, and <textarea> is treated carefully so it is not mangled.

A real example

Suppose you paste this single line: <div><p>Hello</p><p>World</p></div>. With Beautify and a 2-space indent, the result becomes four readable lines: the <div> at column zero, each <p>Hello</p> and <p>World</p> indented two spaces, and the closing </div> back at column zero. Switch to Minify and a neatly indented version of the same block collapses back down to that one compact line, which here trims roughly 30 percent of the bytes that came from spaces and newlines alone.

Common questions

Is this HTML formatter free to use?

Yes. This HTML beautifier and minifier is completely free, has no sign-up, and places no limit on how many times you can run it.

Does my HTML get uploaded to a server?

No. To minify HTML online here, everything is processed by JavaScript inside your own browser. Nothing is sent to any server, so it is safe for private or unreleased markup.

How much can minifying compress my HTML markup?

It depends on how much whitespace, indentation, and how many comments the original file has. Heavily formatted pages often shrink by 20 to 40 percent before any server-side gzip compression is even applied.

Will the beautifier break my JavaScript or CSS?

The tool leaves the contents of script, style, pre, and textarea blocks untouched so inline code and preformatted text are not reformatted or broken.

Can I switch between beautify and minify quickly?

Yes. Use the tabs at the top to choose a mode, then click Format HTML. You can paste the output back into the input and run the other mode to compare results.