ForHosting KIT · Developer Utilities

Minify CSS code and measure the size reduction

Readable stylesheets often contain indentation, line breaks, explanatory comments, and final semicolons that browsers do not need.

● BetaFree · in your browser
Use it from WebAPIEmailTelegramApp soon

This CSS code minifier removes that delivery overhead while keeping quoted strings, selector order, declarations, and rule structure intact. It returns the compact CSS together with the original and minified UTF-8 byte counts and a percentage reduction, making the result useful both as a build artifact and as a measurable optimization. The operation is deterministic, runs without network access, and rejects input whose curly braces are not balanced.

What the minifier removes

The minifier focuses on formatting that is unnecessary when a browser receives a stylesheet. It removes block comments, collapses runs of spaces and line breaks, removes spacing around structural punctuation, and drops the final semicolon immediately before a closing curly brace. It does not reorder rules, merge selectors, rename custom properties, shorten colors, or perform mathematical rewrites. That conservative boundary matters because CSS behavior depends on source order, specificity, and the exact contents of some values. Quoted strings are scanned separately, so comment-like text, spaces, braces, and punctuation inside a quoted URL or generated content value remain untouched. Escaped quote characters are respected as part of the same string. Spaces that separate ordinary tokens are kept when removing them could join two words or values. The result is compact enough for routine delivery while remaining close to the submitted source, which makes unexpected output easier to inspect. Use the returned CSS as a generated asset and keep the readable original in source control for maintenance.

How validation and measurement work

Before returning a result, the scanner tracks every opening and closing curly brace that appears outside comments and quoted strings. A closing brace without an earlier opening brace, or any opening brace left at the end, produces an invalid input error instead of partial minified code. This check catches common copy-and-paste mistakes and truncated stylesheets early. The capability also rejects missing or empty CSS, unfinished comments, and unfinished quoted strings because those inputs cannot be minified predictably. Size figures are measured as UTF-8 bytes rather than JavaScript character counts. That distinction is important for stylesheets containing non-ASCII font names, localized generated content, or Unicode selectors, where one visible character can occupy multiple bytes during transfer. The reduction percentage is calculated from the two byte counts and rounded to two decimal places. Because the same deterministic scanner handles every request without using network calls, random values, clocks, or external state, identical input always returns identical CSS and metrics. This makes the output suitable for repeatable builds, tests, and deployment checks.

Using the result in a delivery workflow

A typical workflow keeps formatted CSS as the editable source and minifies only the copy destined for a website, application bundle, email template, or static asset host. Submit the complete stylesheet, read the compact value from the css field, and write that value to the deployment artifact. The original_bytes and minified_bytes fields can be recorded in build logs, while reduction_percent provides an immediate human-readable measure of the saving. A continuous integration job can compare those metrics between releases to spot accidental growth, although file size budgets should use the exact byte fields rather than a rounded percentage. The scanner is deliberately a minifier rather than a full CSS compiler: it does not resolve imports, add vendor prefixes, validate every property, transpile new syntax, or combine multiple files. Run those transformations first if your project needs them, then minify their final CSS output. If brace validation fails, correct or regenerate the source instead of publishing a truncated result. API automation costs $0.002 per request, while the pure implementation can also support a browser-side experience without sending stylesheet content to another service.

Prepare a production stylesheet

Turn a readable, commented stylesheet into a compact deployment asset while retaining the original source for maintenance.

Measure CSS optimization

Record exact UTF-8 byte counts and the percentage reduction in a build report or performance review.

Validate generated CSS structure

Reject truncated generator output when its rule braces are not balanced before that output reaches a deployment.

What does the CSS minifier remove?

It removes block comments, unnecessary whitespace around CSS structure, and a trailing semicolon before each closing brace.

How much does an API request cost?

Each API request costs $0.002.

How is the reduction percentage calculated?

It compares the original and minified UTF-8 byte counts, then rounds the percentage reduction to two decimal places.

What happens when braces are unbalanced?

The request fails with an invalid input error instead of returning incomplete or potentially misleading CSS.

Are comments or braces inside strings removed or counted?

No. Quoted content is preserved, and braces inside quoted strings do not affect structural brace validation.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/dev2/minify-css

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/dev2/minify-css \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"css":"/* Theme */\n.card {\n  color: red;\n  padding: 1rem;\n}\n"}'
{
  "css": "/* Theme */\n.card {\n  color: red;\n  padding: 1rem;\n}\n"
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "dev2.minify_css",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Read the full KIT documentation →