What is CSS Formatter?
A CSS Formatter reformats your input for readability without changing its meaning. It parses the source, applies consistent indentation, spacing and casing, and returns a clean copy you can paste back into your project. Paste minified or messy CSS, get clean indented output.
CSS Formatter
Beautify and indent CSS in your browser. Powered by js-beautify; no upload.
TLDR
Paste minified or messy CSS and click Run. The page uses js-beautify's css_beautify (the same engine VS Code, Prettier, and most online formatters use) to produce 2-space-indented, single-rule-per-line output. Useful for inspecting third-party stylesheets and cleaning up scraped CSS.
About this CSS formatter
A CSS formatter (sometimes called a beautifier or pretty-printer) takes a stylesheet, parses it, and re-emits the same rules with consistent indentation, one declaration per line, and predictable spacing around selectors, colons, and braces. The semantic meaning is unchanged: every selector still matches the same elements, every property still resolves to the same value. Only the whitespace and casing change. This page wraps the open-source js-beautify library (the same engine that powers the CSS beautifier inside Brackets, Sublime Text plugins, and many web IDEs) so the output matches what you would get running npx js-beautify --css at the terminal.
You typically reach for a formatter when you have minified, hand-mangled, or browser-extracted CSS and you need to read it. Examples: a print stylesheet pulled out of a third-party theme, the contents of a <style> tag scraped from a competitor's homepage, the output of an old Sass compile with no source map, or a chunk of inline CSS pasted from chat. Re-formatting takes one second and turns a 4 KB single-line blob into a 6 KB readable file.
How the formatter works
The page runs entirely in your browser. On Run, we invoke js-beautify's css_beautify with a two-space indent. The library tokenizes the input into selectors, blocks, declarations, comments, and at-rules, then walks the token stream emitting one declaration per line with normalized whitespace.
output = window.css_beautify(input, {
indent_size: 2, // two spaces per nesting level
selector_separator_newline: true,
newline_between_rules: true,
end_with_newline: true,
});
The transform is purely textual. It does not resolve @import URLs, does not flatten Sass or Less syntax, and does not compute specificity. Pass the post-compilation CSS, not the source language.
Worked example: minified rule to formatted
Input (a single-line minified block, 184 bytes):
.card{background:#fff;border:1px solid #e2e8f0;border-radius:12px;padding:16px}.card h3{margin:0 0 8px;font-size:16px;color:#0f172a}.card p{margin:0;font-size:14px;color:#475569}
After js-beautify with two-space indent (251 bytes, 17 lines):
.card {
background: #fff;
border: 1px solid #e2e8f0;
border-radius: 12px;
padding: 16px;
}
.card h3 {
margin: 0 0 8px;
font-size: 16px;
color: #0f172a;
}
.card p {
margin: 0;
font-size: 14px;
color: #475569;
}
Formatter options compared
| Tool | Indent default | Quote style | Strengths | Trade-off |
|---|---|---|---|---|
| js-beautify css_beautify | 2 spaces (configurable) | Preserves input | Stable, predictable, no opinions on color or shorthand | Does not re-order declarations |
| Prettier (with parser: css) | 2 spaces | Double quotes for strings | Opinionated, matches your repo's other Prettier output | May re-order vendor prefixes; needs Node |
| stylelint --fix | Configurable per rule | Configurable | Enforces a style guide and fixes selectors, ordering, and shorthand | Requires a .stylelintrc and Node toolchain |
| CSSTidy | Tab or 2 spaces | Single quotes | Old but battle-tested; preserves browser hacks | Unmaintained since 2010; misses modern CSS features |
| This page | 2 spaces | Preserves input | Zero install, runs in browser, free | Single canned profile; no Sass support |
Common pitfalls
- Pasting Sass, Less, or Tailwind source. The formatter assumes plain CSS. A
@mixinbody or a Tailwind@applyrule may format but the engine does not understand the syntax and may rewrap incorrectly. Compile to CSS first or use the dedicated Sass formatter. - Expecting comment preservation in every position. js-beautify keeps comments where it can, but inline comments between two declarations in the same rule may shift to a leading position. Verify before pasting into production.
- Confusing format with lint. A formatter does not flag invalid colors, unknown properties, or unused selectors. Pair this tool with stylelint for that work.
- Pasting CSS-in-JS strings with template-literal interpolation. A line like
color: ${theme.primary};is not valid CSS once the tagged template runs. Format the rendered output, not the source template. - Losing source-order significance. CSS cascade depends on declaration order. The formatter never reorders declarations, but if you copy paste between blocks you may accidentally change cascade. Format then visually diff against the original.
- Forgetting that the output is regenerated whitespace. Production CSS should be minified, not formatted. Run a CSS minifier before deploying to keep network bytes small.
Related developer tools
Frequently asked questions
Is this css formatter free?
Yes - free forever, no signup, no daily limit. Everything runs in your browser.
Where does my code go?
Nowhere. The transform runs entirely in your browser. Nothing is uploaded, stored, or logged.
Does it work offline?
After first load, yes. The CDN-loaded libraries cache in your browser and the page works without a connection.
Is the output exactly the same as my IDE?
Very close - the library is the same one most IDEs use under the hood (js-beautify for HTML/CSS/JS; Terser for JS minification; js-yaml for YAML). Spacing and line-break choices may differ by a few characters versus Prettier.
Will it handle very large files?
Yes up to several megabytes. For 10+ MB inputs the browser may freeze briefly during processing.
Will the minified output break in older browsers?
Minifiers do not introduce new syntax - they just shorten what is already there. If the input ran on Internet Explorer 11, the minified version still does. For modern ES2022+ syntax check your Babel/SWC config separately.
Does the formatter / minifier preserve comments?
Formatter: yes by default. Minifier: depends. Terser drops all comments unless they look like /*! ... */ legal headers. CSS / HTML minifiers strip all comments unless preceded by `!`.
Can I run this on a whole codebase?
Not in one click - this tool processes one file at a time. For a whole codebase use prettier --write . / eslint --fix / terser --compress in your CI. This tool is for quick one-off paste-and-format.
Is the source map preserved when minifying?
No - the tool minifies in place and returns just the minified code. For production builds that need source maps, run Terser in your bundler (Webpack/Vite/esbuild) where the source-map pipeline is wired in.
How does this compare to Prettier?
Prettier is opinionated and reformats more aggressively (line length, trailing commas, quote style). js-beautify is conservative - it preserves most stylistic choices and just fixes indentation + whitespace. Use Prettier for team-wide style consistency; use this for ad-hoc inspection.
