CSS Minifier
Minify CSS locally with conservative rewrite profiles and byte-savings metrics, while preserving protected comments and flagging release risks.{{ summaryTitle }}
{{ summaryLine }}
{{ computation.values.minified_css }}
The chart renderer is unavailable. Exact byte values remain in the transformation ledger.
| Check | Status | Evidence | Next step | Copy |
|---|---|---|---|---|
| {{ row.check }} | {{ row.status }} | {{ row.evidence }} | {{ row.next_step }} |
| Stage | Count | Effect | Review note | Copy |
|---|---|---|---|---|
| {{ row.stage }} | {{ row.count }} | {{ row.effect }} | {{ row.review }} |
Introduction
Readable CSS contains indentation, line breaks, comments, and deliberately expanded values. Those choices help people review a stylesheet, but most of them are not needed by the browser. Minification removes dispensable text and shortens selected values so the same rules take fewer UTF-8 bytes.
The hard part is preserving token boundaries and cascade behavior. A space may be optional beside a brace but necessary between two names. Text inside quotes must remain text. Removing an earlier declaration may change support for older browsers even when a later declaration uses the same property. Relative asset paths still depend on where the final stylesheet is published.
| Change | Typical purpose | Boundary to check |
|---|---|---|
| Whitespace removal | Drop layout characters that do not separate tokens. | Strings, escapes, operators, and identifier-like tokens still need valid boundaries. |
| Comment removal | Discard author notes from production text. | Comments beginning with /*! often carry licenses or attribution. |
| Value shortening | Turn equivalent zeros and colors into shorter forms. | Newer color syntax may not fit an older browser policy. |
| Duplicate cleanup | Remove an earlier property or join adjacent identical selectors. | Intentional fallbacks and cascade ordering require regression tests. |
Minification and transport compression solve different problems. Minification changes the stylesheet text before release. Gzip or Brotli compresses that text while it travels over the network. A file can benefit from both, and a large raw percentage reduction does not predict the same percentage over gzip.
Nor is minification the same as optimization of a whole site. It does not find unused selectors, combine separate files, rebase asset URLs, inline imports, add browser fallbacks, or prove that the rendered page is unchanged. The minified stylesheet still needs the build, browser, and visual checks required by the project.
The safest release choice is the smallest rewrite boundary that meets the size goal. More aggressive cleanup can save additional bytes, but it also increases the amount of behavior that must be tested.
How to Use This Tool:
Choose how much rewriting is acceptable before treating the output as a release artifact.
- Paste, drop, or load one stylesheet of no more than 2 MiB into CSS source. Close any unfinished comment or string and balance braces, brackets, and parentheses when validation stops.
- Select a Minify profile. Whitespace only keeps the narrowest boundary, Safe production minify also shortens conservative values, and Aggressive cleanup additionally reviews simple duplicates and adjacent identical selectors.
- Set Comment handling and Browser target. Preserve protected comments unless the release policy explicitly allows their removal; use the browser target as a rewrite choice, not as proof of compatibility.
- Inspect the byte result and Release audit. If URL normalization, aggressive cleanup, imports, modern syntax, or an external source map is involved, test the copied stylesheet from its final location before publishing it.
Technical Details:
CSS is a token stream rather than ordinary prose. A conservative minifier therefore tracks quoted strings, escapes, comments, and delimiter depth while it removes whitespace. It preserves a separating space when adjoining characters could otherwise merge into a different token.
Transformation Core
| Stage | Applied rule | Important limit |
|---|---|---|
| Structural scan | Reject unclosed strings or comments and unbalanced braces, brackets, or parentheses. | This is a focused delimiter check, not a complete CSS conformance test. |
| Compaction | Remove selected comments, compact retained comments, collapse whitespace, and drop the final semicolon before a closing brace. | Quoted content remains untouched. |
| Value rewriting | Remove eligible zero units, shorten repeated hex pairs, and convert valid comma-form RGB colors to hex. | Modern mode may also emit eight-digit hex from eligible RGBA values. |
| URL normalization | Remove quotes only from simple url() values without spaces, quotes, parentheses, or backslashes. | Relative paths are never rebased. |
| Aggressive cleanup | Within simple flat rules, keep the last repeated property and merge adjacent identical selectors. | Fallback declarations and cascade assumptions can change. |
| Source-map handoff | Append a map reference and produce a version 3 map containing the original source. | The map has an empty mappings field, so it is not token-level debugging data. |
Formula Core
Size metrics count UTF-8 bytes in the pasted source and final stylesheet. The map file itself is not added to the output-byte figure, although its reference comment is.
If a 1,200-byte stylesheet becomes 780 bytes, 420 bytes were removed and the displayed reduction is 35.0%. When an added map reference makes the output larger than the input, saved bytes may be negative but the reduction percentage is shown as 0% rather than a negative saving.
Strict release review changes warning coverage only; it does not perform extra rewrites. Fair comparisons keep the same source, profile, comment policy, browser target, URL policy, and source-map choice.
Limitations and Privacy:
Stylesheet text is processed locally and is excluded from the share URL. A generated source map is different: it embeds the original CSS, so publishing or sharing that map can disclose comments, internal names, paths, and source that the minified file no longer shows.
- Test the minified file in the actual browser support matrix; the selected target is not a compatibility engine.
- Review
@importdependencies separately because imported stylesheets are not included in this pass. - Run cascade and visual regression tests after aggressive duplicate cleanup.
- Confirm license and attribution obligations before stripping protected comments.
References:
- CSS Syntax Module Level 3, World Wide Web Consortium.
- Comments in CSS, MDN Web Docs.
- The @import CSS at-rule, MDN Web Docs.