CSS, HTML & JS Minifier

Minification removes comments and unnecessary whitespace from CSS, HTML and JavaScript so files download faster. Paste your code below to minify it safely and see how many bytes you save.

Reviewed by ToolNook editorial team Updated Sources

Language

–

What is minification?

Code written for people is full of things browsers do not need: indentation, line breaks, comments and spaces around punctuation. Minification removes them, producing a smaller file that behaves exactly the same. Smaller files download faster, especially on mobile connections, which improves page speed and Core Web Vitals scores.

This minifier is deliberately conservative. It never renames variables or rewrites logic, so the output is safe to drop straight into a page. It understands strings, template literals and regular expressions in JavaScript, keeps /*! license */ comments, leaves <pre> and <textarea> content untouched in HTML, and minifies inline <style> and <script> blocks too.

How to use it

  1. Choose CSS, HTML or JavaScript. An example loads so you can see the result.
  2. Paste your own code into the left box.
  3. Copy or download the minified output. The size before and after is shown underneath.

What gets removed

LanguageRemovedKept
CSSComments, line breaks, spaces around { } : ; , >, last semicolonsStrings, spaces inside calc(), descendant selectors
HTMLComments, repeated whitespace, spaces next to block-level tagspre, textarea, conditional comments, single spaces between inline elements
JavaScriptComments, indentation, spaces around operators, safe line breaksNames, strings, template literals, regular expressions and line breaks that automatic semicolon insertion relies on

When to use a build tool instead

For production websites with a build step, tools such as esbuild, Terser or Lightning CSS go further: they rename local variables, remove unused code and bundle modules. Those tools typically shrink JavaScript by a further 20–40%. Use this minifier for quick jobs, snippets, email templates, CMS custom code fields and sites without a build process.

Also remember that servers compress text with gzip or Brotli. Minification and compression work together: minify first, then let the server compress.

More worked examples

Stylesheet: a 189-byte CSS snippet with comments and indentation shrinks to 137 bytes, a 27.5% saving, before server compression is applied.

Common mistakes to avoid

  • Editing minified files. Keep the readable source and minify a copy.
  • Skipping server compression. Minify and also enable gzip or Brotli on the server.
  • Expecting full optimization. Build tools also rename variables and remove unused code. Format JSON with the JSON formatter.

Sources and methodology

The calculations on this page follow these published standards and references. The code is covered by automated tests against known values.

Frequently asked questions

Will minified code still work?

Yes. Only characters that do not affect behavior are removed, and our automated tests run minified JavaScript to check that it produces the same results as the original.

Can I un-minify code?

Comments cannot be recovered, but you can restore readable formatting with a code beautifier. For JSON, use our JSON formatter.

Why are some line breaks kept in JavaScript?

JavaScript sometimes uses line breaks to end statements (automatic semicolon insertion). Removing them there could change the meaning, so the minifier keeps them.

Is my code uploaded?

No. Minification runs entirely in your browser, so private or unreleased code stays on your machine.