Code minifier

Shrink HTML, CSS, JavaScript and JSON with Terser, CSSO and html-minifier-terser, open-source minifiers that parse the code before they touch it. See the size before and after gzip, and any syntax error at its exact line.

  • Parses the code, no blind search-and-replace
  • Shows the saving before and after gzip
  • Runs in your browser, nothing uploaded
Ready In your browser

Result

Paste code to start

Language —
Saved —
Before
—
After
—
Gzipped
—
  1. Code
    —
    Pasted or opened
  2. Language
    —
    Detected or chosen
  3. Parsed
    —
    Read by the minifier
  4. Minified
    —
    With your options

Minified code

Options

Changes apply at once.

Output

Press Minify to see the result.

What a code minifier does

A minifier removes everything a browser does not need, so files download faster. A good one changes nothing the browser does with them.

What gets removed

Spaces, line breaks and comments that only help people read. In JavaScript, unreachable code goes too, and long local names become one letter.

Parsed, not search-and-replace

A rule like "remove spaces around colons" turns .menu :hover, any hovered item inside the menu, into .menu:hover, the menu itself. A parser knows the difference.

Minify, then compress

Gzip or Brotli on your server compress files while they are sent. Use both: the gzip sizes in the report show what is left after each step.

Minified is not secret

Anyone can run minified code through a beautifier. Keep passwords and private API keys out of browser code.

Languages and what each minifier removes

The engine behind each language, and what it changes.

LanguageEngineWhat it removes or shortens
HTML html-minifier-terser 7.2.0 Comments, whitespace between tags, redundant attributes; inline CSS (with CSSO) and JavaScript minified too. PHP tags are left as written
CSS CSSO 5.0.5 Comments, whitespace, shorter values (#ff0000 to red, 0px to 0); rules can be merged
JavaScript Terser 5.51.2 Comments, whitespace, unreachable code, long local names; modern syntax kept
JSON Built-in, lossless Whitespace outside strings; every value copied exactly

How to use this tool

From readable source to a smaller file for your live site.

  1. Paste or open code

    Paste code, open a file up to 5 MB, or try the example. The language is detected for you.

  2. Check the options

    Pick the language if detection guesses wrong, and decide whether license comments stay.

  3. Minify

    Press Minify. The sizes before and after, and after gzip, appear at once and update as you edit.

  4. Test, then deploy

    Copy or download the result, test it on a staging copy, and keep your readable original.

What this tool does, and what it doesn't

A plain list, so you know exactly what to expect.

This tool does

  • Minify HTML, CSS, JavaScript and JSON
  • Use minifiers that parse the code first
  • Show syntax errors at their line
  • Measure the size before and after gzip
  • Keep license comments if you choose
  • Run in your browser

This tool does not

  • Upload your code anywhere
  • Hide or protect your code
  • Create source maps
  • Read TypeScript, JSX, SCSS or Less
  • Remove unused CSS or bundle files
  • Make code readable again (use the beautifier)

Where your data goes

Nowhere. Your code is minified in your browser and files are read on your device. The first time you minify a language, your browser downloads that open-source minifier from cdn.jsdelivr.net (about 60 KB for CSS, 210 KB for JavaScript and 290 KB for HTML, compressed); your code is not sent with that request. Like any website, our server keeps normal access logs of page visits, as described in our privacy policy.

Why minify, by Chrome for Developers

Why your results might look unexpected

The six situations people run into most, and what each one means.

TypeScript or JSX fails

Terser reads JavaScript only. Compile the code first, then minify the output.

A feature stopped working

Code that reads function names, or another script calling a renamed function. Choose "Keep all names" or Script mode.

Spaces between words vanished

Full whitespace collapse can join inline elements. Use "Keep one space" for HTML.

Savings look small

The code was already minified, or most of it is text and data that cannot shrink.

Gzip saving is smaller

Expected: gzip already compresses repeated spaces, so the download shrinks less than the file.

Minifier did not load

An extension or network blocked cdn.jsdelivr.net. JSON still works.

Questions about minifying code

Can minifying break my code?

It can, but much less often with a minifier that parses the code. Terser, CSSO and html-minifier-terser read the code into a structure first, so strings, regular expressions and selectors stay intact. The usual problems are code that relies on function or class names, other scripts that call your functions by name, and HTML where removed spaces change how inline text looks. The options cover these cases. Test the minified file before you deploy it, and keep the original.

Is my code uploaded to your server?

No. Minifying runs in your browser. The first time you minify a language, your browser downloads that minifier from cdn.jsdelivr.net; your code is not sent there either. Files you open are read on your device. Like any website, our server keeps normal access logs of page visits, as described in our privacy policy.

How much smaller will my files get?

It depends on how the code is written. Indented, commented code often shrinks by a third or more; code that is already minified barely changes. The report also shows the size after gzip, which is closer to what visitors download, because servers compress files in transit. That saving is smaller, since gzip already squeezes repeated spaces well.

Do I still need gzip or Brotli if I minify?

Yes. They do different jobs: minifying removes characters from the file itself, and gzip or Brotli compress the file while it is sent. Most hosts and CDNs, including Cloudflare, compress text files automatically. Using both gives the smallest download.

Will my functions still work when other scripts call them?

In Script mode, yes: names at the top level, such as a function used in an onclick attribute, are kept, and only names inside functions are shortened. ES module mode also shortens top-level names, because a module cannot be reached by name from outside. If code reads its own function names, choose "Keep all names".

Why does it show an error instead of minifying?

A minifier that parses code needs valid code. A missing bracket, an unclosed string or an unclosed tag attribute stops it, and the tool shows the line and column. Terser reads JavaScript only, so TypeScript and JSX must be compiled first, and CSSO reads plain CSS, not SCSS or Less.

Does minified code hide my source?

No. Anyone can run minified code through a beautifier and read it again, with shorter names. Never put passwords or private API keys in code that runs in the browser. The tool also does not create source maps; for those, use a build tool such as Vite, esbuild or webpack.