HTML, CSS and JavaScript minifier
Reduce the size of your HTML, CSS or JavaScript: comments and extra whitespace removed, strings and regex preserved, savings shown. Processed locally.
- Free
- No sign-up
- No file uploaded
- Windows, Mac, Android, iPhone
Loading the tool…
About this tool
Paste HTML, CSS or JavaScript, or open a file: the code is stripped of comments and unnecessary whitespace, with the size before and after. Minification is safe: strings, template literals, regular expressions and pre content are kept intact.
When to use it
Shrinking a small page
For a static page, an HTML email, an ad banner or an embeddable widget, minifying reduces the download size without setting up a build tool.
Embedding code in an attribute or string
One-line CSS or script is easier to paste into a tag manager, a CMS or a config field that doesn't accept line breaks.
Estimating minification savings
Before setting up a build pipeline, measure how much your files would weigh once minified, on top of the server's gzip or brotli compression.
How to use
- Choose the language and paste the code.
- Compare the size before and after.
- Copy or download the minified code.
How it works
The code is read character by character: quoted strings, JavaScript template literals and regular expressions are copied verbatim. Comments are removed, except those starting with /*! (licences). Whitespace is removed wherever it does not separate two words.
In JavaScript, a line break is kept where automatic semicolon insertion might depend on it, so the code's behaviour never changes. In HTML, spaces between inline elements are kept (they are visible), pre and textarea content is untouched, and style and script tags are minified with their own language.
Tips for best results
- Always keep the readable version of your code: the minified version is only for deployment.
- Also enable gzip or brotli compression on your server: it adds up with minification.
- For a full project, a build tool (Vite, esbuild, Terser) also shortens variable names and removes unused code.
- Test the page after minifying, especially older JavaScript that relies on line breaks.
- /*! … */ licence comments are kept: don't strip them from libraries you redistribute.
Common problems and fixes
My JavaScript no longer works
This is rare thanks to the kept line breaks, but code mixing divisions and ambiguous regular expressions can cause trouble. Use a tool such as Terser for that file.
The savings are small
Code that is already compact or has no comments gains little. Big savings come from renaming variables, which a build tool does.
Spaces disappeared between two words
Between two inline elements, the space is kept; around block tags (div, p, li) it is removed because it isn't displayed. Check which tags are involved.
Frequently asked questions
Is my code uploaded?
No. Minification happens entirely in your browser; the code never leaves your device.
Are variable names shortened?
No, on purpose: that requires full program analysis. The tool only removes what is safe to remove.
Are HTML conditional comments kept?
Yes, [if IE]-style comments are kept; other HTML comments are removed.
Can I un-minify code?
For JSON, use the JSON formatter; for SQL, the SQL formatter. Minified JavaScript can be pretty-printed in the Sources tab of the browser's developer tools.
Related searches
Still stuck?
Ask on the forum: the category, the tool, your device sheet and the test result will be filled in for you.