About HTML Formatter / Minifier
The HTML Formatter / Minifier beautifies compact or poorly-indented HTML into clean, nested markup, or minifies readable HTML down to a smaller file by stripping comments and collapsing whitespace between tags. Both modes run from the same input box in your browser.
Beautify mode is for the moment HTML arrives with no formatting at all — copied from a CMS's raw output, extracted from a browser's 'View Source', or generated by a script that doesn't pretty-print — and needs to be readable enough to actually review or edit. Minify mode is for the opposite case: readable, well-commented markup that's ready to ship, where trimming whitespace and stripping development comments shaves a small but real amount off the page weight before it goes to production.
Beautify mode uses js-beautify's HTML formatter, which understands block versus inline elements well enough to indent nested tags sensibly rather than just inserting a newline after every angle bracket. Minify mode here is intentionally a lightweight whitespace-and-comment minifier — it removes HTML comments (except IE conditional comments, which start with `<!--[if`, since removing those can break legacy conditional layouts) and collapses runs of whitespace between tags — rather than a full build-tool-grade minifier that also rewrites inline `<script>`/`<style>` content or restructures attributes.
For most static pages, snippets and email templates, whitespace-and-comment stripping accounts for the large majority of realistic HTML minification gains anyway, since HTML doesn't compress the way JavaScript variable renaming does. If a project needs deeper minification (inlined and minified `<script>`/`<style>` blocks), that's a good use case for the JavaScript and CSS tools alongside this one, applied to those blocks individually. Everything processes locally — HTML containing internal tooling or unpublished content never leaves your browser.
How to Use the HTML Formatter / Minifier
- Paste HTML into the input box.
- Choose Beautify to format it, or Minify to compress it.
- Pick an indent size for Beautify mode.
- Copy or download the result.
Features
- Beautify with js-beautify's HTML-aware formatter
- Minify by stripping comments and collapsing inter-tag whitespace
- Preserves IE conditional comments during minification
- 2 or 4-space indent options for beautified output
Examples
Beautifying compact markup
Input
<div class="card"><h2>Title</h2><p>Some text.</p></div>
Output
<div class="card"> <h2>Title</h2> <p>Some text.</p> </div>
Minifying by stripping a comment and whitespace
Input
<div> <!-- note --> <p>Hi</p> </div>
Output
<div><p>Hi</p></div>
Frequently Asked Questions
Does minify mode touch JavaScript or CSS inside the page?
No — it only strips HTML comments and collapses whitespace between tags. Inline `<script>` and `<style>` content is left as-is; run those blocks through the JavaScript Beautifier/Minifier or a CSS formatter separately for deeper compression.
Will minifying break my layout?
Collapsing whitespace between tags is generally safe for standard HTML, since browsers already collapse most whitespace when rendering block content. The one exception this tool protects: IE conditional comments (`<!--[if ...]-->`) are preserved rather than stripped, since removing them can break legacy conditional markup.
How does beautify decide indentation for inline elements?
It follows standard HTML block/inline conventions — block-level elements like `<div>` and `<p>` get their own indented line, while inline elements like `<span>` and `<a>` typically stay on the same line as surrounding text, matching how most code editors format HTML.
Is the HTML Formatter / Minifier free?
Yes, the HTML Formatter / Minifier is completely free with no usage limits. No signup, no account and no installation required.
Is my data safe?
Yes. All processing happens locally in your browser using JavaScript — nothing you type is uploaded or stored on our servers.
Related Tools
JavaScript Beautifier / Minifier
Beautify minified JavaScript into readable code, or minify it to shrink file size. Free online JS formatter — runs entirely in your browser.
CSS Minifier & Beautifier
Minify CSS to shrink file size or beautify it into readable, indented code. Free online CSS formatter — instant and client-side.
HTML Entity Encoder
Encode special characters as HTML entities or decode entities back to text. Handles named, decimal and hex entities.
HTML to Markdown
Convert HTML to clean Markdown — headings, lists, links, images and code blocks. Free client-side HTML to Markdown converter.
XML Formatter / Validator
Format XML into readable, indented markup or validate it for structural errors. Free online XML formatter and validator.
Email Signature Generator
Create a professional, table-based HTML email signature with your name, title, contact details and social links — ready to paste into Gmail or Outlook.
String Escape / Unescape
Escape or unescape strings for JavaScript, JSON, HTML, SQL or CSV contexts. Free online string escaping tool, runs in your browser.