HTML Formatter & Minifier
Pretty-print HTML with Prettier’s HTML parser, or collapse whitespace between tags with a simple Minify pass. Paste markup, choose Pretty or Minify, and copy the result. Scripts are not executed; this is not a sanitizer or HTML5 repair tool. Formatting runs in this browser.
Written by the CaseSwitch editorial team. We maintain these tools in the browser so drafts, keys, and images stay on your device.
Last reviewed: 23 July 2026
Processed locally in your browser. Nothing is sent to a server.
Paste or type text to convert. Output stays empty until there is input.
Character count: 0 · Word count: 0 · Line count: 0
Examples
Pretty-print nested list
Input
<div><p>Hi</p><ul><li>a</li><li>b</li></ul></div>
Output
<div>
<p>Hi</p>
<ul>
<li>a</li>
<li>b</li>
</ul>
</div>Minify indented markup
Input
<div>
<p>Hi</p>
<ul>
<li>a</li>
</ul>
</div>Output
<div><p>Hi</p><ul><li>a</li></ul></div>
Section with heading
Input
<section><h1>Title</h1><p>Body</p></section>
Output
<section> <h1>Title</h1> <p>Body</p> </section>
Full document skeleton
Input
<html><head><title>T</title></head><body><p>x</p></body></html>
Output
<html>
<head>
<title>T</title>
</head>
<body>
<p>x</p>
</body>
</html>Inline anchors may stay compact
Input
<a href='/x'>link</a><span>y</span>
Output
<a href="/x">link</a><span>y</span>
How to use
- Paste HTML into the input panel. Pretty print is the usual starting mode.
- Switch to Minify only when you want a compact fragment and you know spaces between tags are not content.
- Copy the result. Review `pre`, `textarea`, and inline link spacing before shipping.
What this tool is for
Copied CMS blobs, email HTML, and one-line templates are hard to read. Pretty mode nests tags with Prettier’s HTML parser. Minify collapses runs of whitespace and tightens tag gaps. It is a text rewrite for humans and demos — not an HTML5 fixer, accessibility auditor, or XSS sanitizer.
How it works
Pretty mode formats with Prettier (HTML parser, indent default 2). Minify replaces whitespace runs with a single space and removes spaces between adjacent tags (`> <` → `><`). Be careful with `pre`, `textarea`, and inline elements where space is content — minify is “safe-ish,” not layout-aware.
When to use it
Cleaning an email HTML snippet, reviewing a CMS export, shrinking a static fragment for a demo, and making a nested list readable before you edit it by hand.
When not to use it
JSX/TSX belongs nearer the TypeScript Formatter. XML/SVG with stricter rules may fit the XML Formatter better. Do not minify a content page until you check visible spaces between links. Do not paste HTML you then open as a file without scanning scripts.
How it compares to related tools
HTML to Markdown converts meaning to Markdown. XML Formatter is for well-formed XML. Markdown Formatter is for md source. Longer notes belong in your editor’s HTML plugin for whole sites.
Common mistakes
Minifying until `pre` code samples collapse. Indenting Vue/Svelte files until mustaches look wrong. Assuming minify removes `script` tags — it does not. Treating format as sanitization.
Pretty print versus minify
Pretty print is for reading and editing. Minify is for smaller demos and some transport cases. Neither mode validates HTML5, removes event handlers, or fixes unclosed tags the way a dedicated sanitizer would. If spaces between inline elements matter to readers, prefer pretty print.
Scripts and templates
Formatting does not execute scripts. Still treat pasted HTML as untrusted if you open it as a file. Framework templates (Vue, Svelte, Angular) often need their own formatters — Prettier HTML may mangle mustaches or custom blocks.
Frequently asked questions
Will minify remove spaces between links?+
It can collapse whitespace that users see between inline elements. Prefer pretty print for content pages; minify when the HTML is layout-only or you have verified spacing.
Does this execute scripts in the HTML?+
No. It only rewrites text. Do not paste HTML you then open as a file without scanning scripts.
Is this an accessibility auditor?+
No. It does not check alt text, landmarks, or contrast. Use dedicated a11y tools for that.
Can I format JSX here?+
Simple markup may format, but TypeScript/JSX snippets belong on the TypeScript formatter.
Is my HTML uploaded?+
No. Formatting runs in this browser.
Will it fix unclosed tags?+
It is a formatter, not a repair tool. Broken markup may fail to format or look worse — fix structure first.
Does this tool send my payload to CaseSwitch?+
No. Formatting, encoding, and naming conversions for this page run in your browser after load — your sample stays on the device.
Related guides
Read our original articles on this topic.
Related tools
CSS Formatter
Inspecting a production CSS file, cleaning a snippet from Stack Overflow, teaching cascade with readable examples, and preparing a small style review.
JavaScript Formatter
Reading a minified function from DevTools, cleaning a gist, sharing a snippet in a ticket, and normalizing a short example before a PR comment.
HTML to Markdown
Moving a CMS export toward a README, turning an email into notes, grabbing a heading structure, and starting a docs PR from HTML you already have.
TypeScript Formatter
Cleaning a type copied from a library .d.ts, reviewing a generic-heavy snippet, preparing a PR comment, and normalizing a short TSX-ish example.
SCSS Formatter
Cleaning a mixin you copied, reviewing a theme file fragment, preparing a style PR comment, and teaching nesting with a readable example.
XML Formatter
Debugging an API that still speaks XML, cleaning an SVG you will edit by hand, reading a Maven pom snippet, and comparing two responses visually.