Skip to content
Utilboxes

HTML Formatter

Indent tangled HTML into a readable structure, or strip it down for production.

Runs entirely in your browser

How to use the HTML Formatter

  1. 1Paste your HTML.
  2. 2Press Format to indent it, or Minify to compress it.
  3. 3Set your preferred indentation width.
  4. 4Copy the result or download it.

How it works

The formatter tokenises the markup into tags, text, comments and doctype declarations, then re-emits it with indentation tracking the nesting depth. Void elements such as img, br and input do not increase the depth, since they never close.

Some content must not be touched. Text inside pre and textarea is whitespace-significant — reindenting it changes what the page displays. Script and style blocks contain other languages entirely, where reindentation could break a template literal or a string. All four are passed through verbatim.

Minifying collapses whitespace between tags, removes comments and drops trailing spaces, while applying the same protections. It is a safe structural minify rather than an aggressive one: attribute quotes and optional closing tags are left alone, because removing them is where minifiers break pages.

The markup is only ever handled as text. It is never inserted into this page, so pasting hostile HTML here cannot execute anything.

Everything runs in this page. Nothing you paste is transmitted, logged or stored, which is what makes it safe to drop a production payload in here while you are debugging.

Frequently asked questions

Will formatting change how my page renders?
No. Whitespace between block-level tags is not significant, and the places where it is — pre, textarea, script and style — are left exactly as they were.
How much does minifying save?
Typically 10–25% on indented HTML before gzip. After gzip the difference is smaller, since compression already handles repeated whitespace well.
Is it safe to paste HTML with scripts?
Yes. The markup is processed as text and never rendered, so nothing in it runs.