HTML Formatter
Format messy or minified HTML with proper indentation, using a real HTML parser that also formats embedded CSS and JavaScript correctly. Syntax errors are reported with a line number.
- Files never leave your device
- Free, no signup
- No watermarks
- Works offline once loaded
How to html formatter
- 1
Paste your HTML
Minified, badly indented or hand-written — it all works.
- 2
Choose indentation
2 spaces, 4 spaces or tabs.
- 3
Copy the result
Or download it as an .html file.
Why HTML is stricter about whitespace than it looks
Most HTML tolerates a formatter reflowing its whitespace freely — extra indentation between block-level elements like `<div>` and `<p>` has no visible effect, because browsers collapse runs of whitespace between such elements when rendering. Three specific cases break that assumption entirely: content inside `<pre>` renders every space and line break literally, exactly as written; `<textarea>` treats its content the same way since it is meant to reproduce exact user-editable text; and any element carrying `white-space: pre` in CSS inherits the same literal treatment. A formatter that reflows whitespace inside any of those blocks changes what the page actually displays, not just how the source looks — which is why this formatter leaves them completely untouched rather than applying its usual indentation rules.
Inline elements sitting directly next to text are a subtler case: a space between two inline elements is sometimes visually significant — the gap between two words spanning separate `<span>` tags, for instance — so the formatter is deliberately conservative around inline content, preferring to leave ambiguous whitespace as-is rather than risk collapsing a space that was doing real visual work.
Formatting a whole page in one pass, not just the tags
A page assembled as a single HTML file commonly embeds its own CSS inside a `<style>` block and its own JavaScript inside a `<script>` block, and a formatter that only understands HTML tags would either leave that embedded code as an unformatted blob or, worse, mangle it by treating curly braces and semicolons as HTML syntax. Handing the content of those blocks off to a real CSS parser and a real JavaScript parser respectively means the whole file — markup, styles and behaviour together — comes back consistently formatted, rather than only the outer HTML structure.
Why browsers accept broken HTML and a formatter cannot
Browsers are built with an error-recovery model specifically designed to render something reasonable even from badly malformed markup — an unclosed tag, a missing quote, elements nested in an invalid order — because the web has decades of imperfect HTML in production that still needs to display. A formatter cannot adopt that same leniency: to reformat a document it has to build an accurate structural understanding of what is nested inside what, and a document with genuinely unbalanced tags has no single correct structure to recover. This is why a page that displays completely normally in a browser can still be rejected by this formatter — the browser silently repaired the ambiguity in its own way, while a tool trying to reformat correctly has to flag the ambiguity rather than guess.
Templating syntax is a common false alarm
A file that fails to format is very often not broken HTML at all, but a template — Handlebars, Jinja, Blade, EJS or similar — that mixes templating directives with markup, producing a document that is not valid standalone HTML on its own and never needs to be. The template only becomes real, well-formed HTML after its templating engine has run and substituted in the actual data. Formatting the rendered output, captured after the template engine processes it — from a browser's "View Source," for instance — sidesteps this entirely, since that output is real HTML with no templating syntax left in it.
Frequently asked questions
Does it format CSS and JavaScript inside the page?
Yes. Content inside `<style>` and `<script>` is handed to the CSS and JavaScript parsers, so an entire single-file page formats correctly rather than leaving those blocks untouched.
Will formatting change how my page renders?
Almost never, but not quite never: HTML treats whitespace as significant inside `<pre>`, `<textarea>` and elements with `white-space: pre`. Those are left exactly as they are. Inline elements can shift by one space in edge cases, which is why the formatter is conservative around them.
Why does it reject my HTML?
Usually genuinely unbalanced tags, or template syntax such as Handlebars, Jinja or Blade that is not valid HTML. Browsers silently repair broken markup; a formatter has to understand the structure, so it cannot.
Is my markup uploaded anywhere?
No. The parser runs in your browser, so unreleased pages and client work stay on your machine.
Common html formatter tasks
You might also need
CSS Formatter
Beautify or minify stylesheets
JavaScript Formatter
Format JS and TypeScript with a real parser
JSON Formatter
Format, validate and minify JSON instantly
Base64 Encoder & Decoder
Encode and decode Base64 and Base64URL
CSS Minifier
Shrink stylesheets with a real CSS-aware minifier
Hash Generator
MD5, SHA-1, SHA-256, SHA-384 and SHA-512
JS Minifier
Shrink JavaScript with real minification, not regex
JWT Decoder
Decode and inspect JSON Web Tokens