ToolsHub4u

Remove comments and whitespace from CSS

Paste CSS to remove comments, collapse whitespace and drop the last semicolon in each block. The page reports how many characters were saved.

  • Strings preserved
  • Exact saving
  • No rewriting
Ready Developer & Utility
1Enter
2Adjust
3Copy result

CSS Minifier

1

CSS input

Options

Both changes are safe for valid CSS. The minifier never removes a space that separates two selectors or two values.

No data yet Live
2

Minified CSS

Reduced 205 to 141 characters (31.2% smaller).

Characters saved

64

Minified CSS

  • Whitespace was collapsed, not deleted blindlyA single space is kept where it separates selectors or values. Spaces around braces, semicolons, commas and combinators are removed.
  • Values were not rewrittenColours, units, URLs and custom properties keep their text. No selector merging or property shortening takes place.
  • Comments removedLicence comments and source-map hints are also removed when comments are on. Keep a copy of the original if they matter.
Before
205 chars
After
141 chars
Saved
31.2%
Comments found
1

Minification only removes characters. Confirm that no rule depended on whitespace inside a selector, and keep the original file. A build-pipeline minifier can do more, but it needs tests.

This page removes characters from CSS without rewriting values. It collapses runs of whitespace, drops spaces around braces, semicolons, commas and combinators, removes comments if you ask it to, and can delete the last semicolon in each block. The result is smaller CSS that should behave the same as the input, and the stats show the before and after size.

It is a text minifier, not a compiler. It does not merge rules, shorten colours, rename custom properties or remove unused declarations. Those transformations need a parser and a test suite, because they can change behaviour. This page only takes out characters that valid CSS does not need, and it leaves the places where whitespace is load-bearing alone.

What it removes

Whitespace between tokens is collapsed to a single space where a space is still needed. Spaces around {, }, ; and , are removed, as are spaces around the child and sibling combinators >, + and ~. A space that separates two selectors, such as the descendant combinator, is kept. A space between two values, as in 1px solid #ddd, is also kept.

Comments are removed when the option is on. That includes licence headers and source-map hints. With the option off, each comment is copied exactly, including its internal spacing, so /* keep this spacing */ survives character for character. The surrounding CSS is still minified; the comment is not.

The last-semicolon option removes the semicolon before a closing brace. That is safe in CSS: the final declaration in a block does not need a terminating semicolon. If the option is off, the semicolon stays.

Where whitespace is preserved

CSS requires whitespace around + and - inside calc(), min(), max() and clamp(). Those functions are copied as whole units rather than run through the punctuation pass, so calc(50vh + 10px) and clamp(1rem, 2vw + 1rem, 3rem) come back exactly as written. Nested parentheses and commas inside them are handled the same way.

Quoted strings are preserved too. A content value containing braces, commas or repeated spaces is copied whole, so a label does not lose its text. url() is treated as a function and copied as written, including a quoted path with a space or a data URI with semicolons.

The protection is token-based: the tool finds the opening function or quote and copies through the matching close. It is not a full CSS parser, so an unclosed quote or an unusual vendor function is worth checking by eye. Everything outside those protected pieces is plain text and is minified normally.

A worked example

A 148-character stylesheet with a comment, a custom-property block and a card rule containing calc() and min() was reduced to 108 characters, a saving of 27%. The comment count was one.

Minification results for four inputs
InputOptionsResult
Four rules with calc(), 148 charactersComments, last semicolon108 characters, 27% smaller
Comment kept, 47 charactersNeither option40 characters; comment spacing intact
div > p + span ~ a, 43 charactersComments28 characters; selectors joined
Quoted content and url(), 65 charactersComments55 characters; both values intact

The first output removed the comment and the spaces around braces and colons, then joined the declarations. The calc(50vh + 10px) and min(10px, 20px) values came back unchanged, which is the part that used to break. The var(--gap) reference was left alone.

The kept-comment run is the check for the second fix: the comment still reads /* keep this spacing */ with all three spaces between the words. Only the rule around it was compacted. The selector run shows the normal behaviour outside protected pieces, where div > p + span ~ a becomes div>p+span~a without changing what it selects.

Check unusual valuesFunction contents and quoted strings are copied whole, but the tool is not a parser. Scan the output for an unclosed quote, an unfamiliar at-rule or a custom property whose value depends on spacing.

Comments, licences and source maps

Removing comments is often the biggest saving in a documented stylesheet, and it is also the riskiest. A licence that requires its notice to remain in the distributed file should not be stripped. Some build tools preserve comments that start with /*!; this page does not make that distinction, so turn the option off or add the notice back if your licence needs it.

A source-map comment such as /*# sourceMappingURL=app.css.map */ is also removed when comments are on. If you minify a file that has a map, the map will no longer point at the right place after the text changes. Regenerate the map from the build, not from this output.

Checking the result

Paste the output back into the CSS beautifier and compare the rules with the original. That will not prove equivalence, but it makes the structure visible and helps spot a missing brace or a broken value. For anything important, load the page and check the affected component in a browser.

Keep the original file. Minification is one-way in practice: the output is harder to edit and the comments are gone. The code diff checker can compare the original and the minified text if you need a record of what changed, though most of the differences will be whitespace.

Questions

Common questions

Short answers about this tool and its limits.

Does it break calc() with a plus sign?

No. calc(), min(), max() and clamp() are copied as whole units, so calc(50vh + 10px) keeps its spaces and stays valid. This was a known fault in an earlier version and is fixed.

Does it shorten colours or values?

No. #ffffff stays #ffffff, 0px stays 0px and custom properties are left as written. It only removes whitespace, comments and the optional final semicolon.

Are comments kept exactly when the option is off?

Yes. Each comment is copied character for character, including internal spacing, while the CSS around it is minified. Turning comments off removes them entirely.

Is removing the last semicolon safe?

Yes for a valid block. The final declaration does not need a terminating semicolon. Keep the option off if your tooling compares text literally or if you prefer a uniform style.

Can it remove unused CSS?

No. It has no knowledge of your HTML or your rendered page. Removing unused rules requires a build tool that scans the content, and even then it needs testing because selectors can be assembled at runtime.

What happens to licence comments?

They are removed along with every other comment when comments are off. If the licence requires the notice to remain, leave the option off or add the notice back to the minified file.

Does it touch data URIs and quoted strings?

No. Quoted strings and url() values are copied whole, so braces, commas and repeated spaces inside them survive. An unclosed quote is the one case worth checking by eye.

Is my CSS uploaded?

No. Minification runs in the browser. There is no account or server copy, and the download is created locally. Nothing is retained after you close the tab.