Web Developer Tools · · 4 min read
How to Beautify and Indent Messy HTML
Use the HTML Beautifier to turn minified or messy HTML into clean, indented markup with 2-space, 4-space, or tab indentation.
To beautify HTML, paste it into the HTML Beautifier, pick an Indent size (2 spaces, 4 spaces, or Tab), and read the formatted result in the output box — it updates instantly as you type or paste, with no button to click.
What the HTML Beautifier does
When HTML has been minified for production, copied out of a browser's "View Source," or just typed in a hurry, it ends up as one long line or with inconsistent spacing that's hard to read or debug. The HTML Beautifier reformats that markup: it adds consistent indentation for every nested tag, puts elements on their own lines, and keeps the structure readable without changing what the page actually renders. It runs on js-beautify, the same formatting engine used by many code editors, loaded directly in your browser.
How to beautify HTML with Toolbench
- Open the HTML Beautifier.
- Paste your HTML into the input box on the left.
- Choose an Indent size from the dropdown: 2 spaces (the default), 4 spaces, or Tab.
- Read the formatted markup in the output box on the right — it reformats live, with no "Beautify" button to press.
- Click Copy to copy the result, or use the Send to → menu to pass the output straight into another tool, such as the HTML Minifier.
There's nothing else to configure — indentation width is the only option, since the engine already preserves your content and attributes exactly as written.
A real worked example
Starting from this single-line, unindented HTML:
<!DOCTYPE html><html><head><title>Demo</title></head><body><div class="card"><h1>Hello</h1><p>Some <b>bold</b> text and a <a href="/x">link</a>.</p><ul><li>One</li><li>Two</li></ul></div></body></html>
With the default 2 spaces indent, the HTML Beautifier produces:
<!DOCTYPE html>
<html>
<head>
<title>Demo</title>
</head>
<body>
<div class="card">
<h1>Hello</h1>
<p>Some <b>bold</b> text and a <a href="/x">link</a>.</p>
<ul>
<li>One</li>
<li>Two</li>
</ul>
</div>
</body>
</html>
Every nested tag drops one indentation level deeper than its parent, and the single-line input becomes a readable document. Note that <head> and <body> are themselves indented one level in from <html> — Toolbench's beautifier indents everything inside the document, including those two top-level sections, not just their children.
How the indent options compare
| Indent setting | What changes | When to use it |
|---|---|---|
| 2 spaces (default) | Each nesting level adds two spaces | Matches most web style guides (Google, Airbnb) and keeps deeply nested markup narrow |
| 4 spaces | Each nesting level adds four spaces | Easier to scan visually; common in some editor defaults and older style guides |
| Tab | Each nesting level adds one tab character | Lets each developer's editor render the indent width they prefer |
All three options leave line breaks, blank lines (up to two in a row), and your actual tags, attributes, and text content untouched — only the indentation and line placement change.
Tips and common mistakes
- It won't fix broken HTML. The beautifier reformats structure; it doesn't close unclosed tags or correct invalid markup. If the output still looks wrong after beautifying, check the original markup for mismatched tags.
- It doesn't wrap long lines. A long attribute value or a line with lots of inline content stays on one line — the beautifier only adds structural line breaks and indentation, not line wrapping at a fixed width.
- Minified HTML beautifies fine, but you'll lose nothing in reverse. If you need the compact version back, use the HTML Minifier on the beautified output — the two tools are inverses of each other.
- Going from CSS or JavaScript? This tool is HTML-only. Use the CSS Beautifier or JavaScript Beautifier for
<style>blocks or<script>blocks you want formatted separately.
Related tools
- HTML Minifier — strip comments and whitespace to shrink HTML for production.
- CSS Beautifier — the same indent-and-format treatment for CSS.
- JavaScript Beautifier — reformat minified or messy JavaScript.
Frequently asked questions
How do I format messy or minified HTML?
Paste it into the HTML Beautifier. It reformats the markup instantly, adding consistent indentation for every nested tag — no button to click, and no account needed.
What's the default indent size?
Two spaces per nesting level. You can switch to four spaces or a tab character using the Indent dropdown above the input box.
Does beautifying change what the page looks like?
No. Beautifying only changes whitespace and line breaks in the source — tags, attributes, and text content are untouched, so the rendered page is identical before and after.
Can I beautify just an inline style or script block?
The HTML Beautifier formats the whole document you paste in, including nested <style> and <script> content, but for CSS or JavaScript on its own, use the CSS Beautifier or JavaScript Beautifier instead.
Is my HTML sent to a server?
No. Formatting runs in your browser using the js-beautify library. If you're signed in, your input syncs privately to your account; if you're signed out, nothing is saved anywhere.
More guides
- How to Beautify and Format JavaScriptUse the JavaScript Beautifier to turn minified or messy JS into clean, indented code with 2-space, 4-space, or tab indentation.
- How to Minify CSS to Shrink Stylesheet File SizeUse the CSS Minifier to strip comments and whitespace from CSS instantly in your browser, with a real before-and-after example.
- How to Beautify and Format CSSUse the CSS Beautifier to turn minified or cramped CSS into clean, indented rules with 2-space, 4-space, or tab indentation.