Developer Formatting

CSS minifier

What to do

Processed in your browser · nothing is uploaded

Local · stops where safety stops
Advertisement
320 × 100

Removes comments and every unnecessary space, and drops the semicolon before each closing brace. Values and selector order are left exactly as they are.

How to use the css minifier

1 Paste the stylesheet.
2 Comments, unnecessary whitespace and the semicolon before each closing brace are removed.
3 Nothing is merged, reordered or rewritten; check the two whitespace cases below.
4 Copy the result, or save it as a file.

The safe transformations are the boring ones, and they are most of the win: whitespace around braces, colons and commas is never significant, comments never affect rendering, and the last semicolon in a block is optional.

Everything beyond that requires understanding the cascade, so it is not attempted. Merging .a{color:red} and .a{padding:0} looks obviously safe and is not, because something declared between them may override one of the two. Nothing here is merged, reordered, renamed or shortened, which is what makes the output predictable.

There are two places where whitespace turns out not to be decoration, and both are worth a check on a large stylesheet. Inside calc() the spaces around + and are part of the grammar: calc(100% + 10px) minifies to calc(100%+10px), which is invalid and dropped by the browser. And a descendant selector ending in a pseudo-class loses its space. .a :hover becomes .a:hover, which is a different selector entirely. The second shape is rare; the first is not.

On whether to bother: over gzip the extra saving is a few percent, so it belongs in a build step rather than in your attention. Older CSS hacks that depend on exact whitespace can also break, though there are few of those left to worry about.

Questions

Comments, unnecessary whitespace, and the semicolon before each closing brace. Nothing else.

MDN, CSS reference
Advertisement
300 × 250
Was this tool any good?
Internal signal only · I use it to find the tools worth rebuilding