Code formatter
Paste CSS, HTML or XML to indent it neatly, or minify it for production.
This free online code beautifier and minifier works in your browser. Everything runs in your browser. What you type is not sent anywhere. All inputs and calculations run locally on your device without server uploads; details on browser processing and storage are set out in the privacy policy.
What each mode does
| Language | Format | Minify |
|---|---|---|
| CSS | One declaration per line, nested @media blocks indented | Removes comments, spaces and the last semicolon in each block |
| HTML | Indents nested tags; script, style and pre blocks are left as they are | Removes comments and spaces between tags |
| XML | Checks the XML is well formed, then indents it | Removes comments and spaces between tags |
Good to know
- Comments starting with
/*!are kept when minifying CSS, since they usually hold licences. - Minifying HTML removes spaces between tags. Where inline elements sit side by side, that can remove a visible space; check the result.
- For JSON use the JSON formatter, and for SQL the SQL formatter.
Worked example: Indenting a minified CSS media query and HTML snippet
Suppose you copy a single-line minified CSS block from a production bundle:
@media (min-width:48rem){.grid{display:grid;grid-template-columns:repeat(3,1fr);gap:1.5rem}.grid>.card{padding:1.25rem;border:1px solid #cbd5e1}}
Choosing CSS, setting indentation to 2 spaces, and clicking Format expands each selector and declaration onto its own indented line (12 lines, 214 characters):
@media (min-width: 48rem) {
.grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 1.5rem;
}
.grid > .card {
padding: 1.25rem;
border: 1px solid #cbd5e1;
}
}
Clicking Minify strips all non-essential spaces, newlines, and comments (/* ... */) back out for production deployment.
Limits and what this tool cannot do
- Covers CSS, HTML, and XML only on this page: This lightweight formatter handles CSS, HTML, and XML markup. For JavaScript, TypeScript, JSON, SQL, PHP, or GraphQL, use the dedicated formatters in the Code Formatters directory.
- Formatting does not fix broken syntax: If your CSS is missing a closing brace
}or your XML has an unclosed tag, indentation will drift after the syntax error. Validate markup with the HTML Validator or XML Validator first. - HTML
<pre>and<code>whitespace: Indenting HTML that relies on whitespace-sensitive inline elements can introduce visible spaces between inline tags if not styled with CSS flex/grid.
Questions
Does formatting change how my code works?
No. Only spaces and line breaks change. Minified CSS and HTML work exactly like the original.
Is there a JavaScript beautifier?
Not yet. JavaScript needs a full parser to format safely.
Is my code uploaded?
No. Everything runs in your browser. What you type is not sent anywhere.
Should I use 2 spaces, 4 spaces, or tabs for HTML and CSS?
Most front-end style guides (including Google HTML/CSS, Prettier defaults, and Tailwind) use 2 spaces for HTML, CSS, and XML because deeply nested DOM trees drift too far to the right with 4-space indentation.
Does minifying CSS or HTML change how the page looks?
Minifying CSS removes comments and extra spaces around braces, colons, and semicolons without changing visual styles. In HTML, collapsing whitespace between inline <span> or <a> elements removes the single space character between them.
Is my proprietary source code sent to an external API?
No. Indentation and minification run entirely inside your browser's JavaScript engine.