HTML Formatter
Paste minified or badly indented HTML and get consistently nested, readable markup. Embedded style and script blocks are tidied in the same pass.
- Runs in your browser
- No sign-up
- Free to use
How to use HTML Formatter
- Paste your HTML into the input editor or open an .html file.
- Choose the indentation (2 spaces, 4 spaces or tabs) and a maximum line length if you want long lines wrapped.
- Select Format HTML.
- Copy the formatted markup or download it as a file.
HTML Formatter features
Proper nesting
Child elements are indented under their parents so the document structure is visible at a glance.
Formats embedded CSS and JS
Code inside style and script tags is beautified along with the markup.
Inline elements respected
Links, spans and emphasis stay on the line with their text instead of being broken apart.
Configurable wrapping
Wrap long lines at 80 or 120 characters, or leave them unwrapped.
Content preserved
Text inside pre and textarea elements is left exactly as written.
Local processing
Your markup is formatted in the browser and not uploaded.
When to use HTML Formatter
- Reading the source of a page that was served minified.
- Cleaning up HTML exported by a CMS, email builder or word processor.
- Standardising indentation before committing a template.
- Finding an unclosed or misplaced tag by seeing the true nesting.
HTML Formatter FAQ
Does formatting change how the page renders?
In almost all cases no. Whitespace between block elements is insignificant. Between inline elements a line break counts as a space, so the formatter keeps inline content together to avoid introducing or removing visible gaps.
Will it fix invalid HTML?
No. It re-indents what you give it and does not add missing closing tags or correct nesting errors. Badly nested markup will, however, look obviously wrong once indented, which helps you find the problem.
Can it format template syntax such as PHP, Blade or Handlebars?
Template tags are generally left intact, but complex template logic can confuse the indentation. Check the result before replacing your source.
What about very large files?
Documents of several megabytes format in a second or two. The limit is your device's memory.
Is the HTML executed?
No. The text is only parsed and re-indented; nothing in it runs.
Why consistent HTML formatting helps
HTML is a tree, and indentation is how that tree is shown in text. When every child sits one level in from its parent, you can see which elements a container holds, where it ends, and whether a closing tag is missing, without counting angle brackets. Minified or machine-generated HTML throws that information away to save bytes.
A formatter restores it by tokenising the markup and writing each block-level element on its own line at the correct depth. Good formatters distinguish block from inline elements, because moving an inline element such as a link onto a new line would insert whitespace into the rendered text. That distinction is what keeps the formatted page looking the same as the original.