Free Online HTML Beautifier
Format messy HTML with clean indentation and line breaks.
Beautifying adds line breaks and indentation. Minifying removes comments and optional whitespace while
keeping the contents of pre, textarea, script, and style
blocks intact.
About the HTML Beautifier
HTML is forgiving, which is convenient when writing it by hand and painful when reading output produced by a framework, a template engine, or a build tool. A page can arrive as one enormous line with nested tables, inline SVG, comments, and data attributes. This tool rewrites that markup with consistent indentation and optional line wrapping, and it can also minify the markup when you need the smallest possible output.
Beautify or minify?
- Beautify: adds line breaks and indentation so the document structure is visible. This is the right choice for debugging, code review, and learning how a page is built.
- Minify: removes HTML comments and collapses whitespace between tags, reducing transfer size. This is useful for a quick size comparison before handing markup to a build pipeline.
The beautifier respects void elements such as br, img, and input, keeps
inline text intact where possible, and wraps attributes when a line grows past your chosen length. The indent
control accepts 2, 4, or 8 spaces, or a literal tab for projects that use tabs. When minifying, the contents of
pre, textarea, script, and style elements are protected so
that meaningful whitespace and JavaScript strings are not damaged.
Formatting changes whitespace and comments, not the structure of the document. Browsers mostly treat runs of
whitespace as a single space, but whitespace can matter in inline layouts and in white-space: pre
contexts, so review the result for pixel-sensitive pages. Always keep the original file under version control
before applying bulk formatting. The tool runs locally and does not upload your markup.
How to use this tool
- Paste HTML into the input box.
- Choose an indent size and a wrap length, or enable minify mode.
- The result updates as you type, and the Format button forces a refresh.
- Copy the result or download it as a .html file.
Frequently asked questions
Will formatting break my template tags?
Common template syntax is treated as text and is usually preserved, but complex templating can confuse any HTML formatter. Keep a copy of the original and check the output.
Why does minified HTML still contain some spaces?
Whitespace inside text, scripts, styles, and preformatted blocks can be significant, so the minifier only removes optional whitespace around tags and comments.
Does beautifying fix invalid HTML?
No. It only changes formatting. Missing closing tags or invalid nesting should be corrected with a validator.