HTML Formatter & Beautifier
Paste minified or messy HTML and get it back with one tag per line and nested indentation, so you can read its structure. The reverse direction, minifying to one line, is one toggle away. Works on full documents and fragments; template tags such as Handlebars {{…}} are kept as text lines.
Why HTML Formatting Matters
Browsers don't care about whitespace inside HTML, but humans do. A minified bundle pulled out of a CDN, a server-rendered fragment from a framework, or a chunk of inherited code copy-pasted from a CMS will routinely arrive as one long line with no breaks. Reading that requires either an editor with format-on-paste or a tool that fixes it in place. Formatting also makes diffs sane — see the text diff tool for what an unformatted vs formatted diff looks like.
Beyond readability, consistent formatting catches real bugs. Mismatched tags, accidentally-nested forms, and unclosed elements all surface visually once the indentation is correct. The formatter doesn't fix invalid HTML, but it surfaces it: indentation gets weird in exactly the spot where the parser had to guess.
How It Works
The HTML is split into tags, text, comments, doctype and CDATA. Every tag goes on its own line, inline tags such as <a> and <strong> included, and the content of each element that is not a void element is indented one level deeper. Text is trimmed. The content of <script>, <style>, <pre>, <code> and <textarea> is kept as a block but each of its lines is trimmed and re-indented.
Minify removes all comments, removes whitespace between tags and collapses every remaining run of whitespace to one space, including inside attribute values, <pre> and scripts. The worked example below shows where both modes change what the page displays.
Common Use Cases
Cleaning up HTML pulled from a view-source: or a network-tab response. Preparing a static fragment to paste into a documentation page or blog post. Generating a minified version of an email template before sending. Inspecting the output of a server-side renderer to verify it matches what you expected. Pair with the JSON formatter when working with API responses that contain embedded HTML strings.
Worked example: does the text survive formatting?
A formatter must not change what a page says. Beautify now uses js-beautify 1.15.1 (the library behind the Code Beautifier, self-hosted), and Minify works on the parsed document instead of on raw text. On October 13, 2026 we took 39 guide articles from this site, ran each through both modes in Chromium 141, rendered the results and compared their visible text with the original: identical in 39 of 39 (beautify) and 39 of 39 (minify), compared exactly, character for character. Before this change the beautifier altered the visible text of all 39.
| Case | Before (v214) | Now |
|---|---|---|
Beautify: <p><b>bold</b> <i>italic</i></p> | every inline tag on its own line: the space between the words could disappear | inline tags stay on their text line (js-beautify's inline list) |
Minify: <pre> line 1
line 2</pre> | whitespace inside pre collapsed | untouched |
Minify: script with // note then a new line | line break collapsed, so the comment swallowed the next statement | script contents untouched |
Minify: title="a b" | spaces inside the attribute value collapsed | attribute values never rewritten |
| Minify: comments | always removed, including IE conditional comments | removed unless you tick Keep comments; conditional comments always kept |
Minify: whitespace between <p> blocks | removed (correct) | removed; whitespace between inline elements becomes one space instead of vanishing |
- Minifying HTML saves little. On these articles minify removed 0.1% of the bytes, because the markup was already compact; gzip or Brotli on the server saves far more. Minify is most useful on hand-indented templates.
- CSS can make whitespace matter. An element styled with
white-space: preorpre-wrapshows its spaces and line breaks, and the minifier cannot see your CSS; wrap such text in<pre>or leave it unminified. - Minify normalises markup. Because it rebuilds the HTML from the parsed document,
<br/>becomes<br>and attribute quotes become double quotes; the page renders the same.
Sources
Checked on .
Related tools
- If the HTML you're cleaning came from a PDF, the PDF to HTML converter converts the PDF straight to semantic HTML with inferred headings and preserved links.
Frequently Asked Questions
Built by Derek Giordano · Part of Ultimate Design Tools