Pular para o conteúdo
POST AI agent ready /v1/minify/css

CSS Minify API - Remove Comments and Whitespace

Strips /* */ comments, collapses all whitespace runs to single spaces, removes spaces around punctuation ({ } : ; , > ~ +), and drops the last semicolon before closing braces. Returns the minified CSS plus byte counts and savings percent.

Parameters

stringrequired

CSS source code to minify.

Code examples

curl -X POST https://api.botoi.com/v1/minify/css \
  -H "Content-Type: application/json" \
  -d '{"code":"body {\n  margin: 0;\n  padding: 20px;\n}\n\n/* reset */\n* {\n  box-sizing: border-box;\n}"}'

When to use this API

Build-step CSS compression

In a static-site build pipeline, pipe each CSS file through this endpoint before writing to the dist folder. Cuts CSS payload size without adding a Node minifier dependency.

Inline critical CSS

Minify above-the-fold styles before inlining into the <head>. The minified version keeps your HTML light while preserving the critical-CSS performance benefit.

User-provided theme minification

When letting users submit custom CSS for their profile or page, minify before saving. Reduces DB storage and response-body size when the style ships to the browser.

Frequently asked questions

Is this lossless?
Yes. The output produces identical rendering to the input. Only comments and whitespace are removed.
Does it preserve CSS custom properties?
Yes. --variable-name declarations and var() references are untouched. Only whitespace and comments around them are optimized.
What about CSS-in-JS or Sass/Less?
The minifier expects plain CSS. Pre-compile Sass/Less to CSS before running. Dynamic CSS-in-JS strings can be passed but runtime expressions (${var}) are left as-is.
Are vendor prefixes preserved?
Yes. -webkit-, -moz-, -ms- prefixes are treated as regular identifiers and passed through. Add them with Autoprefixer before minifying.
How much savings can I expect?
Typical savings for production CSS are 15-30%. Heavily commented or over-formatted files can see 40%+.

Get your API key

Free tier includes 5 requests per minute with no credit card required. Upgrade for higher limits.