Code Minifier

Advertisement

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

FULL WIDTH MODE
Size:
Input Code
Output
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 (, ,

), removes unnecessary quotes around simple attribute values, and eliminates default type attributes like type="text/javascript". The parser respects
 and 

          
Was this tool helpful?
Want to tell us more?
0/500
Want us to follow up?
Thanks for your feedback!

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.