Code Minifier

Available in: English, Español, Deutsch, Français, Ελληνικά, Nederlands, Italiano

Advertisement

Paste your code to minify it and reduce file size, or beautify minified code for readability.

FULL WIDTH MODE
Size:
Input Code
Output
Was this tool helpful?
Want to tell us more?
0/500
Want us to follow up?
Thanks for your feedback!
Advertisement

About This Tool

Code minification is a critical step in modern web development that reduces file sizes by stripping characters unnecessary for execution — whitespace, comments, line breaks, and redundant syntax — while preserving the code's exact functionality. The practice emerged in the early 2000s as web applications grew in complexity and page load speed became a measurable ranking factor for search engines. This tool handles three core web languages. For JavaScript, it applies Terser-style transformations including whitespace removal, comment stripping, and shorthand property optimization while respecting ES6+ syntax features like arrow functions, template literals, and destructuring. For CSS, it follows clean-css patterns — collapsing whitespace, shortening color codes (#ffffff becomes #fff), merging duplicate selectors, and removing redundant semicolons. For HTML, it applies html-minifier techniques: removing comments, collapsing whitespace between tags, and stripping optional closing tags. The tool also provides a Beautify mode that reverses the process — adding consistent indentation, line breaks, and spacing to make minified code human-readable again. This is invaluable for debugging production code or understanding third-party libraries distributed only in minified form. All processing runs entirely within your browser using JavaScript — no code is ever transmitted to a server. This makes the tool safe for proprietary source code, internal APIs, and any code you prefer to keep private. The before-and-after statistics panel shows exact byte savings and compression percentage, helping you quantify the performance impact of minification on your project.

The Science of Code Optimization

Code minification sits within a broader optimization pipeline that has evolved alongside the web itself. In the early days of HTTP/1.0, every kilobyte mattered because connections were slow and browsers made separate requests for each resource. The first minification tools appeared around 2003 — Douglas Crockford's JSMin was among the pioneers, performing simple whitespace and comment removal. Modern minifiers like Terser and esbuild go far beyond whitespace removal. They perform dead-code elimination (removing unreachable branches), constant folding (replacing 60 * 60 * 24 with 86400 at build time), and scope analysis to safely rename local variables to single characters. Advanced minifiers can inline small functions, collapse if-else chains into ternary expressions, and convert function declarations into arrow functions where semantically equivalent. The relationship between minification and compression algorithms like gzip and Brotli is complementary rather than redundant. Minification reduces the unique token count and removes entropy (comments, variable names) that compression algorithms would still need to encode. Pre-minified code compresses 5-15% better than the same code compressed from its original formatted state, because the compressor spends fewer bits encoding whitespace patterns and repeated comment structures. HTTP/2 and HTTP/3 changed the calculus slightly by supporting multiplexed streams, reducing the penalty of multiple small files. However, minification remains essential because bandwidth is still the primary bottleneck on mobile networks, and every byte saved reduces the time before the browser can parse, compile, and execute the code. Google's research shows that a 100 ms improvement in page load time correlates with a 0.6% increase in revenue for e-commerce sites, making minification one of the highest-ROI optimizations available to developers.

How to Use

  1. Select your code type (JavaScript, CSS, or HTML) and paste your code into the input panel.
  2. Choose 'Minify' to compress code for production, or 'Beautify' to format minified code for readability.
  3. View size statistics showing compression percentage. Copy the result or download as a file for your project.

Methodology

JavaScript minification applies a multi-pass approach. The first pass strips all single-line (//) and multi-line (/* */) comments while carefully preserving strings and regular expressions that might contain comment-like sequences. The second pass collapses consecutive whitespace into single spaces and removes whitespace around operators, braces, and semicolons. When safe to do so, it shortens variable names within function scopes — though this tool defaults to a conservative approach that prioritizes correctness over maximum compression. CSS minification goes beyond simple whitespace removal. It normalizes color values (#ffffff becomes #fff, rgb(255,0,0) can become red), merges duplicate selectors, removes the last semicolon in declaration blocks, collapses margin and padding shorthand where all values match, and strips units from zero values (0px becomes 0). These micro-optimizations compound across large stylesheets. HTML minification removes comments, collapses whitespace between block-level elements (where it has no visual effect), strips optional closing tags (</li>, </td>, </p>), removes unnecessary quotes around simple attribute values, and eliminates default type attributes like type="text/javascript". The parser respects <pre> and <script> blocks where whitespace is semantically meaningful.

Understanding Your Results

The statistics panel shows three key metrics: original size, minified size, and percentage saved. Typical results vary by language and coding style. Well-commented JavaScript with generous formatting typically yields 30-50% reduction; terse code with few comments may only save 15-20%. CSS savings usually fall between 15-30%, with large frameworks benefiting most. HTML reduction ranges from 10-25%, since much of HTML consists of tag names and attributes that cannot be shortened. These savings compound with server-level compression. When a web server applies gzip or Brotli compression to already-minified files, the total size reduction from original source to delivered payload often exceeds 80%. This directly translates to faster Time to First Byte (TTFB) and improved Core Web Vitals scores. Always keep your original, readable source files for development and debugging. Use source maps in production to link minified code back to original line numbers in browser developer tools. If a minified result appears smaller than expected, check whether your input already had minimal formatting or whether the tool preserved a section to avoid breaking semantics.

Practical Examples

A front-end developer has a 180 KB JavaScript file with extensive JSDoc comments and generous formatting for team readability. Running it through the minifier reduces it to 95 KB — a 47% saving. After the web server applies Brotli compression, the delivered payload drops to just 28 KB, loading in under 100 ms on a 3G connection. A designer exports a 45 KB CSS file from a design tool. The minifier removes duplicate selectors, shortens color codes, and strips comments, bringing it down to 31 KB. The 31% reduction eliminates a render-blocking delay on mobile devices. A team receives a minified vendor library with no source map. Pasting it into Beautify mode produces clean, indented code they can read and audit for security before including it in their project.

Tips & Best Practices

Always test minified output before deploying to production. While minification should preserve functionality, edge cases in template literals, regular expressions, or ASI (Automatic Semicolon Insertion) can sometimes cause unexpected behavior. Run your test suite against the minified bundle, not just the source. Keep original source files in version control and only minify as part of your build pipeline. Never edit minified code directly — it is virtually unreadable and any manual changes will be overwritten on the next build. For maximum savings, combine minification with tree-shaking (removing unused exports) and code-splitting (loading only what each page needs). Minification addresses syntax-level bloat; tree-shaking addresses dead code. Use the Beautify mode to reverse-engineer minified third-party scripts when you need to understand their behavior but only have access to the production bundle.

Your data is never sent. We collect anonymous usage statistics only. Privacy details

Embed This Tool

Get embed code →

Frequently Asked Questions

What does code minification do?
Minification removes unnecessary characters from code without changing its functionality. This includes whitespace, line breaks, comments, and sometimes shortening variable names. The result is smaller file sizes that download faster, improving website performance and reducing bandwidth costs.
Will minification break my code?
Properly written code should work identically after minification. However, some edge cases can cause issues: JavaScript that relies on function.toString(), CSS with syntax errors, or HTML with malformed tags. Always test minified code before deploying to production. If you encounter issues, try disabling advanced optimizations.
How do I customize the panel layout?
Drag the vertical divider between input and output panels to adjust their relative widths. Use the S/M/L buttons to set panel heights, or drag the bottom edge of any panel to resize vertically. Toggle between side-by-side and stacked layouts with the layout icons. Enable Full Width mode to expand the tool across your entire screen, hiding the sidebar for maximum workspace.
What's the difference between minify and beautify?
Minify removes all unnecessary characters to make code as small as possible - ideal for production deployment. Beautify does the opposite: it adds proper indentation, line breaks, and spacing to make code readable - ideal for debugging minified code or improving code readability. Both preserve the code's functionality.
Is my source code kept private?
Yes. All minification and beautification runs entirely in your browser using JavaScript — no code is ever sent to a server. This makes the tool safe for proprietary source code, internal projects, and any code you want to keep confidential. You can even use it offline once the page has loaded.
Which programming languages are supported?
The tool supports JavaScript (including ES6+ syntax like arrow functions and template literals), CSS, and HTML. JavaScript minification uses Terser-based transformations for reliable, production-quality output. CSS minification collapses whitespace, shortens color codes, and merges duplicate selectors. HTML minification removes comments and collapses whitespace between tags.