Code Minifier
Remove whitespace, comments and unnecessary characters from HTML, CSS, and JavaScript.
Why minify code?
Minification removes all unnecessary characters from source code without changing its functionality. This includes whitespace, line breaks, comments, and optional syntax elements. The result is a smaller file that downloads faster, parses more quickly, and uses less bandwidth. Every kilobyte saved matters โ especially on mobile networks where bandwidth is limited and costly.
Professional websites routinely minify all CSS, JavaScript, and HTML in production builds. Tools like webpack, esbuild, Vite, and Parcel handle minification automatically as part of the build pipeline. This standalone tool is useful for quick one-off minification tasks, testing, or when you need to minify a snippet without setting up a build system.
What gets removed?
- Comments โ both single-line (//) and multi-line (/* */) comments are stripped entirely.
- Whitespace โ spaces, tabs, and newlines are removed or collapsed to the minimum required.
- Optional characters โ trailing semicolons, redundant brackets, and other syntax that languages tolerate but do not require.
HTML minification
HTML minification removes comments (<!-- -->), collapses whitespace between tags, and removes unnecessary newlines and indentation. It preserves content within <pre>, <code>, and <textarea> tags where whitespace is significant. Well-minified HTML can be 10โ30% smaller than the original.
CSS minification
CSS minification removes comments (/* */), collapses whitespace around selectors and properties, removes the last semicolon in each declaration block, and shortens color values (e.g., #ffffff becomes #fff). Advanced minifiers also merge duplicate selectors and remove overridden properties.
JavaScript minification
JavaScript minification removes comments, collapses whitespace, and removes unnecessary semicolons. Advanced minifiers (like Terser or esbuild) go further by renaming local variables to shorter names, inlining constants, and removing dead code. This tool performs basic minification suitable for quick tasks.
Best practices
Always keep unminified source code in version control. Never edit minified files directly โ they are virtually unreadable. Use source maps in development to debug minified code by mapping it back to the original source. For production websites, integrate minification into your build process so it happens automatically on every deploy.
Combine minification with gzip or Brotli compression on your web server for maximum savings. Minification reduces the source size, and compression algorithms like Brotli further reduce the transfer size by 60โ80%. Together, a 100 KB JavaScript file might transfer as only 15โ20 KB.
Frequently asked questions
Does minification affect code functionality?
Basic minification (removing whitespace and comments) never changes functionality. Advanced minification techniques like variable renaming and dead code elimination can theoretically cause issues if the code relies on variable names at runtime (e.g., via eval). This tool performs only safe, basic minification.
How much space does minification save?
Typical savings range from 10% for already-concise code to 60% for heavily commented and indented code. CSS usually sees 15โ25% reduction. HTML sees 10โ20%. JavaScript with many comments can see 30โ50% reduction before advanced optimizations.