CSS & JS Minifier Online — How to Compress and Beautify Code Free

Everything you need to know about minifying CSS and JavaScript for production and beautifying minified code for debugging. Covers all minification options, real-world size savings, when to use a build tool instead, and how to make minified third-party code readable again. All examples link directly to the tool.

Published April 26, 2026 · 10 min read
Skip straight to the tool — minify or beautify in seconds
CSS · JavaScript · Minify · Beautify · No signup · Nothing uploaded
Open CSS & JS Minifier →

What Is CSS and JavaScript Minification?

Minification is the process of removing all characters from source code that are not required for it to execute correctly in a browser. Comments, indentation, newlines, trailing semicolons, and redundant value characters — all stripped out. The result is functionally identical to the original, just smaller.

A well-formatted CSS stylesheet with comments and sensible spacing can minify to 40–65% of its original size. JavaScript with debug logging and block comments often sees 40–55% reduction. When you then combine the minified file with gzip or brotli compression on your server, the effective transfer size drops to 10–25% of the original.

That difference in file size directly affects page load time, Core Web Vitals scores, and Largest Contentful Paint (LCP) — the metric Google uses as a primary ranking signal for page experience.

How to Minify CSS Online (Step-by-Step)

Step-by-step — minify CSS
1
Select CSS and Minify
Go to toollance.com/tools/css-js-minifier. The CSS tab and Minify tab are the defaults.
2
Configure your options
Enable Remove Comments, Shorten Zero Values, and Normalize Colors for maximum compression. Enable Preserve License Comments if your CSS includes third-party library headers.
3
Paste or upload your CSS
Paste your CSS into the left pane. Or click Open to upload a .css file directly — useful for large stylesheets.
4
Read the savings and copy
The minified CSS appears in the right pane. The green savings bar shows bytes removed, percentage reduction, and lines eliminated. Click Copy or Download .css.

How to Beautify Minified JavaScript Online

Beautifying (also called unminifying, formatting, or pretty-printing) takes compressed code and restores readable indentation, newlines, and spacing. The code runs identically — it is just human-readable again. Use this when you need to understand what a minified library or third-party script is doing.

Step-by-step — beautify minified JavaScript
1
Select JavaScript and Beautify
Click the JavaScript tab, then the Beautify / Format tab.
2
Choose your indentation
Select 2 Spaces (most common in JS projects), 4 Spaces, or Tab. This is a personal or team-standard preference.
3
Paste the minified code
Paste any minified JavaScript — including library code copied from node_modules, a CDN, or a browser network request.
4
Read and copy
The formatted code appears in the right pane with proper indentation and line breaks. Click Copy to use it.

CSS Minification Options — What Each One Does

OptionTypical savingsWhat it does
Remove comments5–30%Strips all /* */ comments. Heavily commented codebases see the biggest gains here.
Preserve /*! license commentsKeeps comments starting with /*! even when removing all others. Required for many open-source library distributions.
Shorten zero values1–5%Converts 0px, 0em, 0rem, 0% → 0. Also converts 0.5 → .5. Saves 2–4 bytes per occurrence.
Normalize colors1–4%#aabbcc → #abc, #ffffff → #fff. 3 bytes saved per shorthandable color.

JavaScript Minification Options — What Each One Does

OptionTypical savingsWhat it does
Remove comments5–40%Removes both // line comments and /* */ block comments. High impact in thoroughly documented codebases.
Collapse whitespace10–30%Removes unnecessary spaces, tabs, and newlines. Keeps one space where required between tokens.
Remove console.log/warn/error1–10%Strips all console.* calls. Eliminates debug logging and prevents information leakage in production.
Remove debugger<1%Removes debugger; statements that pause execution in browser DevTools. Always remove before deployment.
Preserve /*! license commentsKeeps license headers even when stripping all other comments.

Real-World Size Savings — What to Expect

Savings vary significantly based on how much whitespace, comment density, and long value strings are in your original CSS or JS. Here are realistic benchmarks:

File typeOriginalAfter minificationReduction
Lightly commented CSS10 KB6–7 KB30–40%
Heavily commented CSS10 KB4–5 KB50–60%
Formatted JS (debug logging)20 KB10–12 KB40–50%
Framework/library CSS50 KB25–35 KB30–50%
Minified + gzip10 KB~1.5–2.5 KB75–85%

The last row illustrates why minification and server compression are used together. Minification alone might get you to 60% of original size. Gzip on top of that brings you to 15–25%. Brotli (the modern alternative) typically achieves another 15–20% reduction over gzip.

Minification vs Compression — Not the Same Thing

These two techniques are frequently confused and serve different roles in the performance stack:

Minification
  • Removes unnecessary characters from source code
  • Done once at build time — permanent
  • Result is still human-readable (after beautifying)
  • Applied by you, the developer
  • Works on CSS, JS, HTML, JSON
  • Reduces file size by 30–60%
Server Compression (gzip / brotli)
  • Binary encoding applied during file transfer
  • Done on every request by the web server
  • Result is binary — browser decompresses it
  • Applied by the server (nginx, Apache, CDN)
  • Works on any text-based file
  • Reduces transfer size by a further 60–80%

The correct order is always: minify first, then let the server compress. Minified text has lower entropy than formatted text — repetitive patterns are reduced — so it compresses significantly better than the original source would.

Why You Must Remove console.log Before Production

Leaving console.log, console.warn, and console.error statements in production JavaScript causes four distinct problems:

  1. Information leakage. Anyone who opens browser DevTools can read your console output. This might reveal API responses, user objects, internal state, authentication tokens, or business logic details you did not intend to expose.
  2. Performance overhead. Each console call has a small cost — particularly console.log calls that stringify complex objects. In hot paths (event listeners, render loops), this adds up.
  3. Larger file size. Debug logging in a real codebase can add 5–15% to your JavaScript bundle size. Removing it is free performance.
  4. Looks unprofessional. Log output visible to users signals that the code has not been properly prepared for production. Security-conscious users notice.

Enable the Remove console.log/warn/error option in the JS Minify tab to strip all console calls automatically. The Remove debugger option strips debugger; statements that would pause execution for any user who has DevTools open.

License Comments — Why /*! Comments Are Different

Many open-source CSS and JavaScript libraries include a license comment at the top of their file. These comments start with /*! rather than /*:

/*! jQuery v3.7.1 | (c) OpenJS Foundation and other contributors | jquery.org/license */

The MIT, Apache 2.0, and GPL licenses all contain clauses that require the license notice to be preserved in distributed copies of the software. Stripping these comments when minifying third-party code included in your bundle may constitute a license violation.

The Preserve /*! license comments option keeps all comments that start with /*! exactly as they are, even when the Remove Comments option strips everything else.

CSS Color Normalization — How #aabbcc Becomes #abc

Hexadecimal CSS colors use 6 digits — two for red, two for green, two for blue (e.g. #ff8800). When both digits of any channel are identical, the color can be expressed in 3-digit shorthand:

  • #ffffff#fff (saves 4 bytes)
  • #000000#000 (saves 4 bytes)
  • #aabbcc#abc (saves 4 bytes)
  • #ff8800 → cannot be shortened (00 → 0 works, but ff8 has no pair)
  • #a1b2c3 → cannot be shortened (no repeated digits)

In a CSS file with many colors — a design system, a component library, or Bootstrap — color normalization can save hundreds of bytes. Combined with all other options, these micro-optimizations compound into meaningful file size reductions.

Zero Value Shortening — Why 0px Should Just Be 0

In CSS, a zero value requires no unit. 0px, 0em, 0rem, and 0% are all equivalent to simply 0. The unit is meaningless when the value is zero — zero of any unit is still zero.

Zero shortening also converts leading zeros: 0.5rem becomes .5rem, saving one character per occurrence. In a stylesheet with many margin and padding declarations, this adds up quickly.

The shortener also collapses quad-zero shorthand properties: padding: 0 0 0 0 becomes padding: 0.

Who Uses the CSS & JS Minifier — Real Use Cases

WhoTaskWhy it matters
Frontend developersMinify CSS/JS before pushing to productionSmaller files = faster Largest Contentful Paint (LCP) and better Core Web Vitals scores
Anyone debugging third-party codeMake minified library code readableUnderstand what a library or plugin is doing without buying a decompiler
Developers preparing a production buildStrip all console.log statementsPrevents leaking user data or internal state to anyone with DevTools open
Open source maintainersMinify while keeping license headersMIT, Apache, and GPL licenses often require the license comment to remain in distributed code
Performance engineersQuantify the exact byte savings from minificationCompare minification ROI before committing to a build pipeline change
Students and learnersUnderstand what minification actually removesThe side-by-side view makes the transformation concrete and educational

When to Use This Tool vs a Build Pipeline

The ToolLance minifier is ideal for one-off tasks, quick experiments, understanding what minification does, and files that are not part of a build system. For production projects, integrate minification into your build pipeline so it runs automatically on every build:

Build toolCSS pluginJS pluginNotes
ViteBuilt-in (esbuild)Built-in (esbuild)Zero-config for most projects
webpackcss-minimizer-webpack-pluginTerserWebpackPlugin (built-in)Most configurable
ParcelBuilt-in (lightningcss)Built-in (SWC)Zero-config
Rolluprollup-plugin-postcss + cssnanorollup-plugin-terserLibrary bundling
Gulpgulp-clean-cssgulp-terserTask runner, full control
PostCSS CLIcssnanoCSS-only pipeline

The ToolLance tool performs structural minification (whitespace, comments, console calls). Build pipeline tools like Terser and esbuild go further with variable name mangling, dead code elimination, and tree shaking — producing significantly smaller bundles for complex applications. Use this tool for single files, learning, and quick deployments without a build system.

Privacy — Your Code Never Leaves Your Browser

All minification and beautification runs locally in your browser using JavaScript. No CSS or JS is sent to any server. This matters for proprietary code — internal tools, unreleased products, and business logic you do not want on a third-party server. You can verify this by opening your browser Network tab and confirming no outbound requests are made when you paste and minify.

Related Tools

After minifying your CSS and JavaScript, you may want to validate the JSON configuration files used in your build pipeline — the JSON Formatter & Validator catches syntax errors instantly. If your JavaScript files include Base64-encoded assets or JWT tokens, the Base64 Encoder & Decoder handles encoding and decoding without uploading anything. Comparing your minified output to a previous version? The Diff Checker highlights every change at the character level.

Frequently Asked Questions

What is CSS minification?

CSS minification removes all characters browsers do not need to parse a stylesheet: comments, whitespace, trailing semicolons, and redundant value characters (0px → 0, #ffffff → #fff). The result is functionally identical but significantly smaller.

How much does CSS minification reduce file size?

Typical formatted CSS with comments minifies to 40–65% of its original size. Combined with gzip or brotli server compression, the effective transfer size is 10–25% of the original.

What is the difference between minification and compression?

Minification removes unnecessary source characters — done once at build time. Compression (gzip, brotli) is a binary encoding the server applies during every file transfer. They work together: minify first, then serve with compression enabled.

Why should I remove console.log from production JS?

console.log in production exposes debug data to anyone with DevTools open, can log sensitive user data accidentally, increases file size, and adds performance overhead. The Remove console option strips all console calls automatically during minification.

What does 'beautify' or 'unminify' code mean?

Beautifying takes minified code and restores proper indentation, newlines, and spacing to make it human-readable. The code runs identically — it is just easier to understand and debug.

What are /*! license comments and why preserve them?

Comments starting with /*! are license headers used by open-source libraries. MIT, Apache, and GPL licenses often require these headers to remain in distributed code. The Preserve License Comments option keeps them when removing all other comments.

How is this different from Terser or UglifyJS?

Terser and UglifyJS perform full optimization including variable name mangling, dead code elimination, and constant folding. This tool performs structural minification only — whitespace and comments. It requires no installation and runs instantly in the browser, making it ideal for quick tasks.

What does normalizing CSS colors mean?

Color normalization converts 6-digit hex colors with repeated channel digits to 3-digit shorthand: #aabbcc → #abc, #ffffff → #fff. This saves 4 bytes per shorthandable color and is safe — the result is identical in all browsers.

Is my code uploaded to a server?

No. All minification and beautification runs entirely in your browser using JavaScript. Nothing is sent anywhere. Safe for proprietary code, unreleased products, and internal tools.

Should I minify manually or use a build tool?

For production projects, integrate minification into webpack, Vite, Parcel, or Rollup so it runs automatically on every build. Use this tool for one-off files, quick experiments, third-party code, and projects without a build system.