Skip to content
T
Tools.Town
Free Online Tools for Everyone
</>

HTML Formatter

100% Free

Format, indent, and prettify messy or minified HTML — or minify it back — entirely in your browser with adjustable indentation.

Beautify & Minify
Instant
100% Client-Side
No Sign Up
Output mode

Input HTML

262 chars · 1 lines

Formatted HTML

31 lines
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>
      Tools.Town
    </title>
  </head>
  <body>
    <div class="container">
      <h1>
        Hello
      </h1>
      <p>
        Welcome to
        <strong>
          Tools.Town
        </strong>
        — your free online toolkit.
      </p>
      <ul>
        <li>
          Fast
        </li>
        <li>
          Free
        </li>
      </ul>
    </div>
  </body>
</html>

Embed This Tool

Easy to Embed

Add HTML Formatter to your website or blog in seconds.

  • Responsive design
  • Lightweight & fast
  • No backend required
  • Always up-to-date
<iframe
  src="https://tools.town/embed/html-formatter/"
  width="100%"
  height="600"
  style="border:none; border-radius:12px;"
  loading="lazy"
  title="HTML Formatter">
</iframe>

Share This Tool

Share Instantly

Share HTML Formatter with anyone — no login required.

  • Shareable link
  • No login required
  • Works on any device
  • No account needed

Share via

Advertisement

How to Use

  1. 1 Paste minified or messy HTML into the input panel
  2. 2 Choose Beautify to indent or Minify to compact
  3. 3 Pick your indentation: 2 spaces, 4 spaces, or tabs
  4. 4 Read the cleanly indented result in the output panel
  5. 5 Copy the formatted HTML with one click

Features

  • Beautify and minify in one tool
  • Adjustable indentation: 2 spaces, 4 spaces, or tabs
  • Preserves the verbatim content of pre, script, and style
  • Void elements never wrongly increase indent depth
  • Live character and line counts
  • Runs entirely in your browser — nothing is uploaded

Why it Matters

Minified or hand-edited HTML is painful to read and review — a single line of markup hides the document's structure. A formatter re-indents the tags so nesting is obvious, which makes debugging, code review, and learning from other people's pages far easier. Minifying does the reverse for production, shaving bytes off the page.

★★★★★

Use Cases

Read Minified Pages

Expand compressed HTML to inspect its structure

Clean Up Templates

Tidy markup before committing or sharing it

Shrink for Production

Minify HTML to reduce page weight

Learn from Source

Indent a page you are studying to follow the nesting

What this tool does

The HTML Formatter re-indents messy or minified HTML so its structure is easy to read, and can also minify clean HTML back down to compact markup. Choose your indentation — two spaces, four spaces, or tabs — and the tool prints each element at a depth that reflects its nesting.

How it works

The formatter tokenises your HTML into tags, text, comments, and doctype, then prints each meaningful node on its own line, increasing the indent for every open tag and decreasing it for every close tag. Void elements and the verbatim content of pre, script, style, and textarea are handled specially so the output stays correct. The logic is a pure function — the same input always produces the same output.

Privacy

Everything runs locally in your browser. No values are uploaded, logged, or stored.

Frequently Asked Questions

What is the difference between beautifying and minifying HTML?
Beautifying re-indents HTML so each element sits on its own line at a depth that reflects its nesting, making the structure easy to read. Minifying does the opposite: it strips insignificant whitespace and comments to produce the smallest valid markup, which is what you want to ship to production. This tool does both.
Will formatting change how my page renders?
For ordinary markup, no — adding or removing whitespace between block-level tags does not change the rendered result. The one place whitespace is significant is inside elements like pre, textarea, script, and style, so the formatter preserves the content of those elements exactly as written rather than re-indenting it.
Does it handle void elements like <br> and <img> correctly?
Yes. Void elements such as br, img, input, and meta have no closing tag, so the formatter prints them on their own line without increasing the indentation depth. That keeps the rest of your document lined up correctly instead of drifting further right after every self-contained tag.
Can I choose tabs instead of spaces?
Yes. The indentation control offers two spaces, four spaces, or a tab character per level, so you can match your project's code style. The choice only affects beautify mode; minify removes indentation entirely.
Is my HTML sent to a server?
No. Formatting runs entirely in your browser with JavaScript. Nothing you paste is uploaded, logged, or stored, and refreshing the page clears everything.

Related Tools You Might Like

Browse more free tools