HTML Formatter, Beautifier and Minifier
Free HTML formatter: beautify messy HTML with proper indentation or minify it for production. Runs in your browser, nothing is uploaded.
Every tag is balanced and no duplicate ids were found.
What Is an HTML Formatter?
An HTML formatter is a tool that rewrites the whitespace in an HTML document so every element sits on its own line, indented to show its nesting, without changing what the browser renders. This page is an html beautifier and an html minifier in one: the Beautify tab makes markup readable, the Minify tab strips it down for production, and a structure check below both lists unclosed or stray tags.
Beautifying uses the js-beautify library, the same engine behind many editor extensions. Minifying and validation are done with a purpose-built scanner. Everything runs in your browser.
How to Format HTML Online
- Paste your HTML into the input pane or open an .html file.
- On the Beautify tab choose the indent (2 spaces, 4 spaces or tab), an optional wrap width, and whether to keep blank lines.
- List any tags to keep unformatted, for example
code, pre, textarea, so their contents are left untouched. - Switch to Minify to collapse whitespace and, optionally, remove comments.
- Check the byte counts in the output header and the structure check for problems.
- Copy the result or download it as an .html file.
Beautifier Options
| Option | Default | What it does |
|---|---|---|
| Indent | 2 spaces | Indent unit per nesting level; tab uses one tab character |
| Wrap at | never | Breaks long lines of text and attributes at 80, 100 or 120 characters |
| Preserve blank lines | on | Keeps up to two blank lines from the source between elements |
| Indent head and body | off | Indents head and body one level inside html, as some style guides require |
| Keep unformatted | code, pre, textarea, script, style | Tags whose inner content and inline position are left exactly as written |
What the HTML Minifier Removes and Keeps
The html minifier removes comments (conditional comments for old Internet Explorer are kept), collapses every run of whitespace to a single space, deletes whitespace next to block-level tags such as div, p, li and table, and trims text inside block elements. Whitespace between inline elements, for example two adjacent spans or a link followed by text, is reduced to one space rather than removed, because removing it would join words. The contents of pre, textarea, script and style are never touched. Attribute values are left as they are.
Why Use an HTML Formatter
Run an HTML formatter on markup exported from a CMS, a mail builder or a markdown converter before you edit it by hand; indented markup makes a missing closing tag obvious, and the structure check catches the ones that are not. Minify before deploying static pages or email templates where every kilobyte counts. If the HTML came from markdown, the Markdown to HTML converter linked below produces clean output to begin with, and the HTML to Markdown converter goes the other way.
Frequently Asked Questions
Does the HTML formatter change how my page renders?
No. The HTML formatter only changes whitespace between tags and keeps the content of pre, textarea, script and style exactly as it was, so the page renders the same. The one caveat is inline elements: a line break between two spans becomes a space in the browser either way, and the formatter preserves that.
How much smaller does the HTML minifier make a file?
Typically 10 to 30 percent for hand-written or template-generated HTML, mostly from indentation and comments. The stats next to the output show bytes before and after. Gzip on the server removes most of the remaining redundancy, so minifying matters most for pages that are not compressed in transit.
What does the structure check find?
It scans the tags and reports elements that are opened but never closed, closing tags with no opening tag, closing tags on void elements such as br, and duplicate id attributes. Tags whose closing tag is optional in HTML, like p, li and td, are not reported.
Can I format HTML online with tabs instead of spaces?
Yes. Set Indent to tab. The formatter also offers 2 or 4 spaces, an optional wrap width, whether blank lines in the source are kept, and whether head and body are indented inside html.
Is my HTML uploaded?
No. The html prettifier and minifier both run in your browser, so pages with unpublished content or embedded keys stay on your device.