CSS Minifier & Code Compressor

Minify CSS stylesheets, strip comments, collapse whitespace, optimize 0-unit values, and reduce payload byte sizes for web applications.

How to Use the CSS Minifier

1

Input CSS Code

Paste any uncompressed CSS stylesheet code, framework rules, or component styles into the text box.

2

Compress Code

Click Minify CSS Code to remove comments, collapse whitespace, and trim unnecessary zero-units.

3

Copy Minified CSS

Copy the compressed CSS output for production web deployments and CDN static assets.

Tool Options

Faster Load Speed

Minifying CSS reduces network payload byte sizes, speeding up First Contentful Paint (FCP) and Google Core Web Vitals.

Zero-Unit Optimization

Automatically compresses 0-unit values (e.g. `0px`, `0em`, `0%` $\rightarrow$ `0`) and strips trailing property semicolons.

Deterministic REST API

Provides a free REST API endpoint (`POST /api/css/css-minifier`) for automated CI/CD build scripts and asset pipelines.

Your Data Privacy

Web Tool
Privacy-First Architecture
Most of our web tools process your data entirely in-browser. Where server processing is technically required, payloads are evaluated statelessly in-memory and are never stored, saved, or logged.
REST API
Stateless In-Memory Processing
When you use our API endpoints, your requests are processed strictly in-memory without persistent database storage, disk logging, or data retention.
Want to learn more about how we safeguard your information and infrastructure?
Read our full Privacy Policy for detailed security standards, data retention principles, and compliance guarantees.

What does the CSS Minifier & Code Compressor do?

The CSS Minifier & Code Compressor strips CSS comments (/* ... */), collapses extra whitespace and line breaks, normalizes zero units (0px $\to$ 0), and trims trailing property semicolons to produce compact, high-performance stylesheet assets.

Core Concepts

Understanding CSS minification rules and AST compression:

  • Comment Stripping: Removes multiline comments (/* ... */) that are non-functional in production runtimes.
  • Whitespace & Delimiter Optimization: Collapses redundant line breaks and strips whitespace around CSS syntax characters ({, }, :, ;, ,).
  • Zero-Unit Normalization: Replaces units on zero values (0px, 0em, 0rem, 0%) with unitless 0 according to CSS specifications.

How to use the tool?

  1. Paste CSS Code: Enter or paste your unminified CSS rules into the editor or click Load Sample.
  2. Configure Settings: Toggle Remove comments to purge comment blocks or leave unchecked to keep licensing headers.
  3. Compress & Export: Click Minify CSS Code, then click Copy or Download to save your compressed stylesheet.

Related Developer Utilities

If you work with web development, stylesheets, and asset optimization, explore these complementary tools:

REST API Integration

Blueutils provides a free REST API endpoint (POST https://blueutils.com/api/css/css-minifier) to programmatically minify CSS stylesheets, strip comments, collapse whitespace, and optimize property rules.

API Request Parameters

Name Type Description Example
rawText String Raw CSS stylesheet payload to minify. ".card { color: red; }"
options Object Optional settings (removeComments: boolean). {"removeComments": true}

API Request Payload Examples

cURL

curl -X POST https://blueutils.com/api/css/css-minifier \
  -H "Content-Type: application/json" \
  -d '{
    "rawText": ".container { width: 100%; margin: 0px auto; }",
    "options": { "removeComments": true }
  }'

Python

import requests

url = "https://blueutils.com/api/css/css-minifier"
payload = {
    "rawText": ".container { width: 100%; margin: 0px auto; }",
    "options": { "removeComments": True }
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.json())

Java

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
    public static void main(String[] args) throws Exception {
        String jsonPayload = """
            {
                "rawText": ".container { width: 100%; margin: 0px auto; }",
                "options": { "removeComments": true }
            }
            """;

        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://blueutils.com/api/css/css-minifier"))
            .header("Content-Type", "application/json")
            .POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
            .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}

API Response Parameters

Name Type Description Example
isValid Boolean Indicates whether minification succeeded. true
minifiedCss String Compressed single-line CSS string. ".container{width:100%;margin:0 auto}"
stats Object Reduction metrics (originalBytes, minifiedBytes, reductionPercentage). {"originalBytes":45}

API Response Payload Examples

Success Response (HTTP 200 OK)

{
  "isValid": true,
  "minifiedCss": ".container{width:100%;margin:0 auto}",
  "result": ".container{width:100%;margin:0 auto}",
  "stats": {
    "originalBytes": 45,
    "minifiedBytes": 32,
    "reductionBytes": 13,
    "reductionPercentage": "28.89%"
  }
}

Validation Failure Response (HTTP 400 Bad Request)

{
  "isValid": false,
  "error": "Invalid input: CSS payload to minify cannot be empty."
}

Rate Limit Exceeded Response (HTTP 429 Too Many Requests)

{
  "error": "API rate limit exceeded. Please wait or contact support@blueutils.com."
}

Why use an API to minify CSS?

Integrating the CSS Minifier API into frontend build pipelines, CMS deployment scripts, or AI agent tool calling provides key benefits:

  • Rapid Script Validation: Prepares optimized static asset bundles before deploying code to edge CDNs and web servers.
  • Optimized Token Efficiency for AI Agents: LLMs generate verbose, multiline CSS styles. Invoking the API compresses stylesheet strings by 30% to 50% without risking invalid property syntax.
  • Deterministic Accuracy Without Hallucinations: Ensures 100% accurate zero-unit conversions and comment stripping without dropping essential selector rules.

Native Usage

How to minify CSS files locally in terminal environments or scripts:

Windows (CMD / PowerShell)

# Minify CSS in PowerShell
(Get-Content -Path .\style.css -Raw) -replace '/\*[\s\S]*?\*/', '' -replace '\s+', ' ' -replace '\s*([{\}:;,])\s*', '$1' | Set-Content style.min.css

Linux / Unix (Bash)

# Minify CSS in Linux using tr and sed
tr -d '\n' < style.css | sed -E 's/\/\*.*\*\///g; s/  */ /g; s/ *([{:;,]) */\1/g' > style.min.css

Python

Using Python re:

import re

with open("style.css") as f:
    css = f.read()

css = re.sub(r'/\*[\s\S]*?\*/', '', css)
css = re.sub(r'\s+', ' ', css)
css = re.sub(r'\s*([{\}:;,])\s*', r'\1', css)
css = re.sub(r';}', '}', css)

with open("style.min.css", "w") as f:
    f.write(css.strip())

print("CSS minified successfully.")

Java

Using Java regex:

import java.nio.file.Files;
import java.nio.file.Paths;

public class MinifyCssExample {
    public static void main(String[] args) throws Exception {
        String css = new String(Files.readAllBytes(Paths.get("style.css")));
        String min = css.replaceAll("/\\*[\\s\\S]*?\\*/", "")
                        .replaceAll("\\s+", " ")
                        .replaceAll("\\s*([{\\}:;,])\\s*", "$1")
                        .replaceAll(";}", "}")
                        .trim();
        Files.write(Paths.get("style.min.css"), min.getBytes());
        System.out.println("CSS minified successfully.");
    }
}

Frequently Asked Questions (FAQ)

How do I minify CSS stylesheets online?

Paste your uncompressed CSS rules into the input box, select comment stripping options, and click Minify CSS Code. The tool collapses spaces and optimizes zero-unit properties.

How does CSS minification improve website performance?

Removing unnecessary spaces, line breaks, and CSS comments reduces network payload size, speeding up First Contentful Paint (FCP) and Google PageSpeed scores.

Is my CSS stylesheet uploaded to remote servers?

No. All CSS minification and rule optimizations execute 100% client-side directly inside your browser. Your stylesheets stay completely private.

Rate Limits

UI Limits
100 uses per 15 minutes
Max payload size: 5 MB
API Limits
5 requests per 60 minutes
Max payload size: 256 KB
Need higher API rate limits, increased payload sizes, or custom developer solutions?
Contact our engineering team at support@blueutils.com for custom rate limit increases, higher quota allocations, or tailored enterprise integrations.