Developer Tools

Code Minifier - Minify JavaScript, HTML, CSS & XML

Free online code minifier that strips comments and whitespace from JavaScript, HTML, CSS and XML right in your browser, with a live byte count.

Published by Free Online Tools Last updated: 11 uses

Language

Press Ctrl + Enter to minify. Your code stays in your browser.

Nothing minified yet

Paste your code and press Minify to see how many bytes you save.

A code minifier makes source files smaller by removing everything a browser or parser does not need: comments, indentation, line breaks and extra spaces. This free online code minifier handles JavaScript, HTML, CSS and XML in one place. Paste your code, pick the language, and you get a compact version plus the exact number of bytes saved, with nothing to install and nothing to upload.

Smaller files download faster, and faster downloads help pages load sooner on slow mobile connections. The tool is also handy when you want a quick check before a deploy and have no build pipeline at hand.

How to use the Code Minifier

  1. Choose the language: JavaScript, HTML, CSS or XML.
  2. Paste your code into the source box, or press Load sample to try an example.
  3. Press Minify, or use Ctrl + Enter (Cmd + Enter on a Mac).
  4. Check the percentage saved and the before and after sizes in the result card.
  5. Press Copy result and paste the minified code where you need it.

How a code minifier works

The tool applies careful text transforms that depend on the language you select. It reads your code, skips over quoted strings so their content is never touched, removes comments, and collapses whitespace wherever that is safe. It is not a full parser, so it does not rename variables or rewrite your logic.

What gets removed in each language

LanguageRemovedLeft untouched
JavaScriptLine and block comments, indentation, extra spaces, most line breaksStrings, template literals, regular expressions, line breaks that protect code without semicolons
CSSComments, spaces around braces, colons, commas and semicolons, the last semicolon in a blockQuoted strings, spaces inside values such as calc()
HTMLComments, repeated whitespace, spaces between block-level tags, extra spaces inside tagsConditional comments, pre and textarea content, spacing between inline elements
XMLComments, whitespace between elements, extra spaces inside tagsCDATA sections and text content

Why the tool plays it safe

JavaScript lets you leave out semicolons, and the engine adds them at some line breaks. If every line break were deleted, code written that way could stop working. The minifier therefore keeps a line break wherever removing it might change the meaning. In CSS, the spaces inside calc(1px + 2px) are required, so they are never stripped.

Worked examples

The examples below show what to expect. The symbol ↵ marks a line break, and there is no line break after the last line.

JavaScript

Input: function add(a, b) {↵ return a + b; // sum↵}. The minifier drops the comment, the indentation, the spaces after the comma and around the plus sign, and the line breaks. The output is function add(a,b){return a+b;}.

OriginalMinifiedSaved
45 bytes30 bytes15 bytes (33.3%)

CSS

Input: .btn {↵ color: #fff;↵ margin: 0 auto;↵}. The output is .btn{color:#fff;margin:0 auto}. The space inside the value 0 auto stays, because the browser needs it to read two values.

OriginalMinifiedSaved
41 bytes30 bytes11 bytes (26.8%)

HTML

Input: <div class="box">↵ <!-- note -->↵ <p>Hello, world</p>↵</div>. The comment disappears, the spaces around the block tags are removed, and the three spaces in the text become one. The output is <div class="box"><p>Hello, world</p></div>, which is 42 bytes instead of 64, a saving of 34.4%.

Benefits and common uses

  • Faster pages: fewer bytes to download means less waiting, especially on mobile networks.
  • Quick pre-deploy checks: compress a script or stylesheet without setting up a bundler.
  • Email templates: trim inline CSS and HTML so templates stay under size limits.
  • Size comparisons: see which files gain the most from minification before you decide where to spend time.
  • Learning: compare input and output to see which characters are safe to remove in each language.

Tips for better results

  • Select the correct language first, because each mode follows different rules.
  • End your JavaScript statements with semicolons. The output will contain fewer line breaks.
  • Keep the original source file. Minified code is difficult to read and edit.
  • Test the minified result in your page or app before you publish it.
  • Serve your files with gzip or Brotli as well. Minifying and server compression stack well.

When a build tool is the better choice

This code minifier removes comments and whitespace only. Production tools such as Terser, esbuild or cssnano also shorten variable names, fold constants and delete unused code, so they usually produce smaller files. Use this page for snippets, quick checks and files that live outside a build pipeline, and let your build tool handle full bundles.

Paste your code, press Minify and see how much you can save.

Frequently asked questions

What is a code minifier?
A code minifier removes comments, extra spaces and line breaks from source code so the file is smaller but does the same job. It is a standard step before publishing JavaScript, CSS and HTML.
Is it safe to paste private or proprietary code here?
The minifier runs entirely in your browser, and this page does not send your code to a server. As with any online tool, avoid pasting secrets such as API keys or passwords.
Will minifying change how my code behaves?
For valid code the behavior should stay the same, because only comments and unneeded whitespace are removed. Test the minified output before deploying and keep your original source file.
How much smaller will my file get?
It depends on how much of the file is comments and indentation. Heavily commented, neatly indented code shrinks the most, while code that is already dense shrinks less.
What is the difference between minifying and gzip compression?
Minifying rewrites the file itself to remove unneeded characters, while gzip or Brotli compresses the bytes during transfer. They work well together, so use both when you can.
Can I minify CSS, HTML and XML as well as JavaScript?
Yes. Pick the language above the editor and the tool applies rules suited to that format, including inline script and style blocks inside HTML.
Why does my minified JavaScript still contain some line breaks?
When a line has no semicolon, removing the break could change how JavaScript reads the code. The tool keeps those breaks to stay safe, so adding semicolons to your source gives a smaller result.
Should I use this instead of Terser or esbuild for production builds?
For production bundles, a build tool such as Terser or esbuild is the better choice because it can shorten variable names and remove dead code. This tool is best for quick checks, small snippets and files you edit outside a build pipeline.