# Code Minifier

> Minify JavaScript, CSS, and HTML with byte-level savings.

Free code minifier. Shrink JavaScript with Terser and CSS with csso, plus a structural HTML pass that strips comments, collapses whitespace, and cleans redundant attributes. Toggle mangling, compression, and aggressive HTML options, then compare before/after byte counts and the savings percentage.

- Page: https://benchline.fabwaseem.com/t/code-minifier
- Runs: in the browser. Input stays on the device.
- Price: free, no account
- Input: Source code plus per-language minifier options.
- Output: Minified code with before/after byte counts and savings %.
- Keywords: javascript minifier, css minifier, html minifier, minify js online, code compressor
- Updated: 2026-10-18
- Built by: Waseem Anjum (https://fabwaseem.com)

## How to use it

1. **Pick a language.** Switch between the JavaScript, CSS, and HTML tabs.
2. **Tune the options.** Turn mangling and compression on or off, pick the CSS optimization level, or enable aggressive HTML mode.
3. **Copy the output.** Read the before/after byte counts and the savings percentage, then copy or download the minified code.

## Use it from an AI agent

MCP tool name: `minify_code`
MCP endpoint: https://benchline.fabwaseem.com/mcp (Streamable HTTP, no key)
HTTP: POST https://benchline.fabwaseem.com/api/v1/tools/code-minifier with the input as the JSON body
This call does not fetch anything. It runs on the arguments you send.

Minify source code with Terser (JS), csso (CSS), or a structural HTML pass and report before/after byte counts.

### Input schema

```json
{
  "type": "object",
  "properties": {
    "language": {
      "type": "string",
      "enum": [
        "js",
        "css",
        "html"
      ]
    },
    "code": {
      "type": "string",
      "minLength": 1,
      "maxLength": 500000
    },
    "jsMangle": {
      "default": true,
      "type": "boolean"
    },
    "jsCompress": {
      "default": true,
      "type": "boolean"
    },
    "cssLevel": {
      "default": 2,
      "anyOf": [
        {
          "type": "number",
          "const": 1
        },
        {
          "type": "number",
          "const": 2
        }
      ]
    },
    "htmlAggressive": {
      "default": false,
      "type": "boolean"
    }
  },
  "required": [
    "language",
    "code",
    "jsMangle",
    "jsCompress",
    "cssLevel",
    "htmlAggressive"
  ],
  "additionalProperties": false
}
```

### Example tools/call

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "minify_code",
    "arguments": {
      "language": "js",
      "code": "example",
      "jsMangle": true,
      "jsCompress": true,
      "cssLevel": 2,
      "htmlAggressive": false
    }
  }
}
```

Setup for Claude, Cursor, and VS Code: https://benchline.fabwaseem.com/mcp/guide

## Questions

### Which minifiers are used?

Terser for JavaScript and csso for CSS — the same engines behind most build pipelines. HTML gets a built-in structural pass: comments, whitespace, and redundant attributes are removed without touching inline scripts or styles.

### Is my code sent anywhere?

No. Minification runs entirely in the browser on this page.

### What does aggressive HTML mode change?

It also removes optional closing tags like </p> and </li>. The output stays valid HTML, but diff it before shipping.

### Why did my JavaScript fail to minify?

Terser parses the code first, so a syntax error stops the run and the message is shown. Fix the reported spot and try again.

## Related tools

- [JSON formatter](https://benchline.fabwaseem.com/t/json-formatter): Pretty-print, minify, and validate JSON, with the exact line and column when it fails.
- [SVG optimizer](https://benchline.fabwaseem.com/t/svg-optimizer): Minify an SVG, compare the size, and keep the viewBox unless you turn that off.
- [Page to Markdown](https://benchline.fabwaseem.com/t/html-to-markdown-url): Fetch a public page and turn the article into Markdown.
- [Markdown HTML](https://benchline.fabwaseem.com/t/markdown-html): Convert Markdown to HTML, or HTML back to Markdown, with a live preview.
