CSS Formatter & Minifier
Prettify CSS code or minify it to reduce file size.
๐ How to Use
Paste the CSS code you want to format or minify.
Click โจ Format to prettify the code, or ๐๏ธ Minify to remove whitespace and newlines.
Use ๐ Copy to save the transformed CSS to clipboard.
About the CSS Formatter
CSS is the language that describes how HTML is painted on screen, but as stylesheets grow they accumulate inconsistent indentation, single-line rules, leftover debug comments, and stray trailing semicolons. This formatter gives you two complementary operations on the same input: Format rebuilds a stylesheet with predictable indentation so it reads cleanly in a code review, and Minify strips every byte that is not strictly necessary so the file ships faster over the network. Both run entirely in your browser — no stylesheet is ever uploaded.
How it works
The formatter starts by parsing the stylesheet into a tree of rules. Each rule has two parts: a selector (the part before the braces, which may be a type, class, id, attribute, or compound selector) and a list of declarations (the property: value pairs inside the braces). At-rules such as @media and @keyframes are handled as nested blocks. Once the input is parsed into this structure, it is re-serialized: pretty-print mode emits each declaration on its own line with the chosen indent (2 spaces, 4 spaces, or a tab), and minify mode joins everything back into the shortest valid string.
Minify removes comments, all non-significant whitespace, and the optional semicolon after the last declaration in a block, while preserving every property value, selector, and at-rule. The critical constraint is that safe reformatting must not change the cascade or specificity: rules keep their original order, selectors are not merged or split, and shorthand properties are left untouched. As long as those invariants hold, formatted and minified output render identically to the original.
Common use cases
- Normalizing indentation before committing a hand-edited stylesheet
- Shrinking a large CSS bundle before deploying to production
- Cleaning up CSS pasted from a minified bundle so it can be read
- Producing a consistent style for an entire design-system codebase
- Stripping author comments and dead whitespace before code review
Worked example
Given messy, single-line input:
.btn{color:#fff;background:#4f46e5;padding:8px 16px;border-radius:6px}
.btn:hover{background:#4338ca}
Formatting with a 2-space indent yields the readable form:
.btn {
color: #fff;
background: #4f46e5;
padding: 8px 16px;
border-radius: 6px;
}
.btn:hover {
background: #4338ca;
}
And minify collapses it back to the smallest valid form, with the trailing semicolons and newlines removed:
.btn{color:#fff;background:#4f46e5;padding:8px 16px;border-radius:6px}.btn:hover{background:#4338ca}
All three forms apply the exact same styles — only the human readability and byte count differ.
Frequently asked questions
Does formatting change how my styles render?
No. The formatter only changes whitespace, newlines, and indentation. It never reorders rules, alters selectors, or modifies property values, so cascade order and specificity are preserved exactly.
What does minify actually remove?
Minify strips comments, removes all non-significant whitespace, and drops optional trailing semicolons. Property values, selectors, at-rules, and the cascade itself are left intact, so the rendered result is identical but the byte count drops.
Are comments preserved when formatting?
Formatting keeps comments intact and re-indents them with the surrounding rules. Minify removes them entirely, since they have no runtime effect and only add bytes to the file.
Is my CSS sent to a server?
No. Parsing and re-serialization happen entirely in your browser. The stylesheet you paste never leaves your device, which makes this tool safe for proprietary design systems and unreleased product styles.
Why does a malformed rule disappear from the output?
The parser is tolerant: a rule with an unbalanced brace or missing block is skipped rather than producing broken CSS. Fix the offending declaration and it will reappear in the formatted or minified result.
CSS ํฌ๋งคํฐ๋?
CSS๋ HTML์ด ํ๋ฉด์ ์ด๋ป๊ฒ ๊ทธ๋ ค์ง๋์ง๋ฅผ ๊ธฐ์ ํ๋ ์ธ์ด์ด์ง๋ง, ์คํ์ผ์ํธ๊ฐ ์ปค์ง๋ฉด ๋ค์ฌ์ฐ๊ธฐ๊ฐ ์ ๊ฐ๊ฐ์ด๊ณ ํ ์ค ๊ท์น, ๋๋ฒ๊ทธ ์ฃผ์ ์ฐ๊บผ๊ธฐ, ๋ถํ์ํ ํํ ์ธ๋ฏธ์ฝ๋ก ์ด ์์ ๋๋ค. ์ด ํฌ๋งคํฐ๋ ๊ฐ์ ์ ๋ ฅ์ ๋ํด ๋ ๊ฐ์ง ๋ณด์์ ๋์์ ์ ๊ณตํฉ๋๋ค. Format์ ์์ธก ๊ฐ๋ฅํ ๋ค์ฌ์ฐ๊ธฐ๋ก ์คํ์ผ์ํธ๋ฅผ ๋ค์ ๋ง๋ค์ด ์ฝ๋ ๋ฆฌ๋ทฐ์์ ์ฝ๊ธฐ ์ข๊ฒ ํ๊ณ , Minify๋ ๊ผญ ํ์ํ์ง ์์ ๋ฐ์ดํธ๋ฅผ ๋ชจ๋ ์ ๊ฑฐํด ๋คํธ์ํฌ ์ ์ก์ ๋น ๋ฅด๊ฒ ํฉ๋๋ค. ๋ ๋์ ๋ชจ๋ ๋ธ๋ผ์ฐ์ ์์๋ง ์ํ๋๋ฉฐ ์ด๋ค ์คํ์ผ์ํธ๋ ์ ๋ก๋๋์ง ์์ต๋๋ค.
์๋ ๋ฐฉ์
ํฌ๋งคํฐ๋ ๋จผ์ ์คํ์ผ์ํธ๋ฅผ ๊ท์น ํธ๋ฆฌ๋ก ํ์ฑํฉ๋๋ค. ๊ฐ ๊ท์น์ ๋ ๋ถ๋ถ์ผ๋ก ์ด๋ฃจ์ด์ง๋๋ค. ์ค๊ดํธ ์์ ์
๋ ํฐ(ํ์
, ํด๋์ค, ์์ด๋, ์์ฑ, ๋ณตํฉ ์
๋ ํฐ ๋ฑ)์ ์ค๊ดํธ ์์ ์ ์ธ ๋ชฉ๋ก(property: value ์)์
๋๋ค. @media๋ @keyframes ๊ฐ์ at-๊ท์น์ ์ค์ฒฉ ๋ธ๋ก์ผ๋ก ์ฒ๋ฆฌ๋ฉ๋๋ค. ์
๋ ฅ์ด ์ด ๊ตฌ์กฐ๋ก ํ์ฑ๋๋ฉด ์ฌ์ง๋ ฌํ๋ฉ๋๋ค. pretty-print ๋ชจ๋๋ ๊ฐ ์ ์ธ์ ์์ฒด ์ค์ ์ ํํ ๋ค์ฌ์ฐ๊ธฐ(2์นธ, 4์นธ, ํญ)๋ก ์ถ๋ ฅํ๊ณ , minify ๋ชจ๋๋ ๋ชจ๋ ๋ค์ ๊ฐ์ฅ ์งง์ ์ ํจ ๋ฌธ์์ด๋ก ํฉ์นฉ๋๋ค.
minify๋ ์ฃผ์, ์๋ฏธ ์๋ ๋ชจ๋ ๊ณต๋ฐฑ, ๋ธ๋ก์ ๋ง์ง๋ง ์ ์ธ ๋ค ์ ํ์ ์ธ๋ฏธ์ฝ๋ก ์ ์ ๊ฑฐํ๋ ๋ชจ๋ ์์ฑ๊ฐ, ์ ๋ ํฐ, at-๊ท์น์ ๋ณด์กดํฉ๋๋ค. ํต์ฌ ์ ์ฝ์ ์์ ํ ์ฌํฌ๋งท์ ์บ์ค์ผ์ด๋๋ ๋ช ์๋๋ฅผ ๋ฐ๊พธ์ง ์์์ผ ํ๋ค๋ ๊ฒ์ ๋๋ค. ๊ท์น์ ์๋ ์์๋ฅผ ์ ์งํ๊ณ , ์ ๋ ํฐ๋ ๋ณํฉ๋๊ฑฐ๋ ๋ถํ ๋์ง ์์ผ๋ฉฐ, ๋จ์ถ ์์ฑ์ ๊ทธ๋๋ก ๋ก๋๋ค. ์ด ๋ถ๋ณ ์กฐ๊ฑด์ด ์ ์ง๋๋ ํ ํฌ๋งท๋ ์ถ๋ ฅ๊ณผ minify๋ ์ถ๋ ฅ์ ์๋ณธ๊ณผ ๋์ผํ๊ฒ ๋ ๋๋ง๋ฉ๋๋ค.
์์ฃผ ์ฐ๋ ๊ฒฝ์ฐ
- ์์ผ๋ก ํธ์งํ ์คํ์ผ์ํธ๋ฅผ ์ปค๋ฐํ๊ธฐ ์ ๋ค์ฌ์ฐ๊ธฐ ํต์ผํ๊ธฐ
- ๋์ฉ๋ CSS ๋ฒ๋ค์ ํ๋ก๋์ ๋ฐฐํฌ ์ ์ ์ค์ด๊ธฐ
- minify๋ ๋ฒ๋ค์์ ๋ถ์ฌ๋ฃ์ CSS๋ฅผ ์ฝ๊ธฐ ์ข๊ฒ ์ ๋ฆฌํ๊ธฐ
- ๋์์ธ ์์คํ ์ฝ๋๋ฒ ์ด์ค ์ ์ฒด์ ์ผ๊ด๋ ์คํ์ผ ์ ์ฉํ๊ธฐ
- ์ฝ๋ ๋ฆฌ๋ทฐ ์ ์์ฑ์ ์ฃผ์๊ณผ ์ฃฝ์ ๊ณต๋ฐฑ ์ ๊ฑฐํ๊ธฐ
์ฌ์ฉ ์
์ง์ ๋ถํ๊ณ ํ ์ค๋ก ๋ ์ ๋ ฅ์ด ์ฃผ์ด์ง๋ฉด:
.btn{color:#fff;background:#4f46e5;padding:8px 16px;border-radius:6px}
.btn:hover{background:#4338ca}
2์นธ ๋ค์ฌ์ฐ๊ธฐ๋ก ํฌ๋งทํ๋ฉด ์ฝ๊ธฐ ์ข์ ํํ๊ฐ ๋ฉ๋๋ค:
.btn {
color: #fff;
background: #4f46e5;
padding: 8px 16px;
border-radius: 6px;
}
.btn:hover {
background: #4338ca;
}
๊ทธ๋ฆฌ๊ณ minify๋ ํํ ์ธ๋ฏธ์ฝ๋ก ๊ณผ ์ค๋ฐ๊ฟ์ ์ ๊ฑฐํด ๋ค์ ๊ฐ์ฅ ์์ ์ ํจ ํํ๋ก ์์ถํฉ๋๋ค:
.btn{color:#fff;background:#4f46e5;padding:8px 16px;border-radius:6px}.btn:hover{background:#4338ca}
์ธ ๊ฐ์ง ํํ ๋ชจ๋ ์ ํํ ๊ฐ์ ์คํ์ผ์ ์ ์ฉํฉ๋๋ค — ๋ฌ๋ผ์ง๋ ๊ฒ์ ์ฌ๋์ด ์ฝ๊ธฐ ์ข์ ์ ๋์ ๋ฐ์ดํธ ์๋ฟ์ ๋๋ค.
์์ฃผ ๋ฌป๋ ์ง๋ฌธ
ํฌ๋งทํ๋ฉด ์คํ์ผ์ด ๋ ๋๋ง๋๋ ๋ฐฉ์์ด ๋ฐ๋๋์?
์๋๋๋ค. ํฌ๋งคํฐ๋ ๊ณต๋ฐฑ, ์ค๋ฐ๊ฟ, ๋ค์ฌ์ฐ๊ธฐ๋ง ๋ฐ๊ฟ๋๋ค. ๊ท์น์ ์์๋ฅผ ๋ฐ๊พธ๊ฑฐ๋ ์ ๋ ํฐ๋ฅผ ๋ณ๊ฒฝํ๊ฑฐ๋ ์์ฑ๊ฐ์ ์์ ํ์ง ์์ผ๋ฏ๋ก ์บ์ค์ผ์ด๋ ์์์ ๋ช ์๋๊ฐ ์ ํํ ๋ณด์กด๋ฉ๋๋ค.
minify๊ฐ ์ค์ ๋ก ๋ฌด์์ ์ ๊ฑฐํ๋์?
minify๋ ์ฃผ์, ์๋ฏธ ์๋ ๋ชจ๋ ๊ณต๋ฐฑ, ์ ํ์ ํํ ์ธ๋ฏธ์ฝ๋ก ์ ์ ๊ฑฐํฉ๋๋ค. ์์ฑ๊ฐ, ์ ๋ ํฐ, at-๊ท์น, ์บ์ค์ผ์ด๋ ์์ฒด๋ ๊ทธ๋๋ก ๋๋ฏ๋ก ๋ ๋๋ง ๊ฒฐ๊ณผ๋ ๋์ผํ์ง๋ง ๋ฐ์ดํธ ์๋ ์ค์ด๋ญ๋๋ค.
ํฌ๋งทํ ๋ ์ฃผ์์ด ๋ณด์กด๋๋์?
ํฌ๋งท์ ์ฃผ์์ ๊ทธ๋๋ก ์ ์งํ๊ณ ์ฃผ๋ณ ๊ท์น์ ๋ง์ถฐ ๋ค์ฌ์ฐ๊ธฐ๋ฅผ ๋ค์ ์ ์ฉํฉ๋๋ค. minify๋ ์ฃผ์์ด ๋ฐํ์์ ์ํฅ์ ์ฃผ์ง ์๊ณ ํ์ผ ํฌ๊ธฐ๋ง ๋๋ฆฌ๋ฏ๋ก ์ฃผ์์ ์์ ํ ์ ๊ฑฐํฉ๋๋ค.
CSS๊ฐ ์๋ฒ๋ก ์ ์ก๋๋์?
์๋๋๋ค. ํ์ฑ๊ณผ ์ฌ์ง๋ ฌํ๋ ์ ์ ์ผ๋ก ๋ธ๋ผ์ฐ์ ์์ ์ด๋ฃจ์ด์ง๋๋ค. ๋ถ์ฌ๋ฃ์ ์คํ์ผ์ํธ๋ ๊ธฐ๊ธฐ๋ฅผ ๋ ๋์ง ์์ผ๋ฏ๋ก ๋ ์ ๋์์ธ ์์คํ ๊ณผ ๋ฏธ์ถ์ ์ ํ ์คํ์ผ์๋ ์์ ํฉ๋๋ค.
์๋ชป๋ ๊ท์น์ด ์ถ๋ ฅ์์ ์ฌ๋ผ์ง๋ ์ด์ ๋?
ํ์๋ ๊ด๋ํฉ๋๋ค. ์ค๊ดํธ ์ง์ด ์ ๋ง๊ฑฐ๋ ๋ธ๋ก์ด ๋น ์ง ๊ท์น์ ๊นจ์ง CSS๋ฅผ ๋ง๋๋ ๋์ ๊ฑด๋๋๋๋ค. ๋ฌธ์ ๊ฐ ๋๋ ์ ์ธ์ ๊ณ ์น๋ฉด ํฌ๋งท์ด๋ minify ๊ฒฐ๊ณผ์ ๋ค์ ๋ํ๋ฉ๋๋ค.