Developer tool

HTML Formatter and Minifier

Paste HTML and choose Format or Minify. The parser runs only in your browser.

Runs in your browser. No upload.

Values are processed locally in this browser.

Result

—

About this tool

HTML Formatter and Minifier made simple.

The minifier keeps comments and does not minify scripts or styles inside the HTML. Whitespace collapsing can affect spacing in visible text, so compare the output and keep your original before replacing a page. This is not a sanitizer.

Guide

Using HTML Formatter and Minifier

The HTML Formatter and Minifier takes a block of HTML you paste in and gives it back in one of two shapes. Format lays the tags out on separate indented lines so a person can read them. Minify removes some of the blank gaps between block tags to make the text a little shorter. It does not fix broken markup, clean unsafe code or check that a page is valid.

How to use it

  1. Paste your HTML into the source box. It must not be empty, and it can hold up to 200,000 characters.
  2. Choose the action: Format to make it readable, or Minify to shorten it.
  3. Press Calculate and read the result below. If the HTML has a broken tag, Format shows an error message instead of output.
  4. Press Copy result to put the output on your clipboard, or Clear to empty the box and start again.

Worked examples

Format a small list

You enter
Action
format
Source
<div><p>Hello <b>world</b></p><ul><li>One</li><li>Two</li></ul></div>
You get
Value
<div ><p>Hello <b>world</b></p ><ul ><li>One</li ><li>Two</li></ul ></div >

Each nested tag moves to its own indented line. The closing bracket sits at the start of the next line, which looks odd but keeps the spacing between tags exactly as typed, because the formatter treats whitespace as meaningful.

Run through the tool’s own code.

Format collapses repeated spaces in text

You enter
Action
format
Source
<p>Hello <em>big</em> world</p>
You get
Value
<p>Hello <em>big</em> world</p>

Runs of spaces inside text become a single space, and the result ends with a newline. The words and tags are unchanged.

Run through the tool’s own code.

Minify a snippet with blank lines between blocks

You enter
Action
minify
Source
<div> <p>Hello world</p> <ul> <li>One</li> <li>Two</li> </ul> </div>
You get
Value
<html><head></head><body><div><p>Hello world</p><ul><li>One</li><li>Two</li></ul></div></body></html>

The blank gaps between the block tags are removed. Two things to notice: the three spaces inside the paragraph stay, and the browser's parser wraps the fragment in html, head and body tags.

Run through the tool’s own code.

When it helps

  • Making a long one-line HTML snippet readable before you edit it or paste it into a bug report.
  • Tidying markup copied from an email template or a page source before a code review.
  • Cutting some of the whitespace in a small HTML file before you put it on a page.

Limits to keep in mind

  • Input must be non-empty and under 200,000 characters. Larger text is refused with a message.
  • Format uses strict whitespace handling, so closing brackets can land at the start of a line. The output is correct but looks unusual.
  • Minify only removes blank text between block-level tags. It does not shorten spaces inside text, and it does not shrink scripts or styles.
  • Minify uses the browser's HTML parser, so the output can include html, head and body tags, and a comment placed before the first tag may be dropped.

Tips

  • Keep your original copy and compare the minified version in a browser before you replace a live file.
  • If Format shows an error, look for an unclosed or mismatched tag near the place the message names.
  • Use a separate CSS or JavaScript formatter for the code inside style and script tags, because this tool leaves it as is.

Common questions

About HTML Formatter and Minifier.

Does the HTML formatter upload my code?

No. Both actions run in your browser, and the pasted HTML is not sent to a server. The result stays in the page until you clear it or close the tab, and Copy result only uses your clipboard when you press it.

Why do the closing brackets look strange after formatting?

The formatter is set to treat whitespace between tags as meaningful, as browsers do for inline text. To avoid adding or removing spaces, it breaks lines inside the tags instead. The page renders the same way as before.

Will minifying change how my page looks?

It can, in small ways. Removing the gaps between block tags usually changes nothing visible, but whitespace between inline items can matter. Compare the output in a browser and keep your original before you replace anything.

Does it minify my script and style code too?

No. The text inside script and style tags is left as you typed it. Use a CSS or JavaScript formatter and minifier for those parts, then paste the result back into your HTML.

Does this tool fix or sanitize bad HTML?

No. Format will show an error for a broken tag and stop. Minify lets the browser's parser repair some mistakes quietly. Neither one removes unsafe code, so never treat the output as cleaned or safe to publish.

Does minify keep HTML comments?

Comments inside the body are kept. A comment at the very start, before the first tag, can be lost in the output, so check the result if you rely on a top comment such as a license note.

Why did minify add html, head and body tags?

The tool reads your text with the browser's own HTML parser, which builds a full page around any fragment. The tags it adds are part of the output, so remove them yourself if you only wanted the snippet.

How do I use HTML formatter?

Paste HTML and choose Format or Minify. The parser runs only in your browser.

Is my data uploaded to a server?

No. This tool runs locally in your browser. Your input is not uploaded.