How to Minify HTML, CSS and JavaScript in the Browser to Cut Page Weight
Learn how the Code Minifier strips comments and whitespace from HTML, CSS and JS, what it leaves untouched, and when to check the output.
Code Minifier (HTML/CSS/JS)
Introduction
Every comment, indent and line break in a stylesheet or script is sent to the visitor's browser and parsed before anything renders. The Code Minifier removes that filler from HTML, CSS and JavaScript with a scanner that recognises strings, comments and other literals, so a snippet can be trimmed for a quick inline embed or a size check without installing a build tool. Everything runs in the browser and the code never leaves the page.
Step-by-Step Instructions
- Select the language tab (HTML, CSS or JS) above the editor so the right set of rules is applied.
- Paste the source into the Raw Input Code box, replacing the sample markup.
- Click Minify Code to produce the compressed version in the Minified Result pane.
- Test the result before shipping it, especially JavaScript, by running it once in the browser console or your page.
- Click Copy next to Minified Result to place the output on the clipboard.
Key Use Cases
- Inline critical CSS: Shrink a small block of above-the-fold styles before pasting it into a style tag.
- Email and widget snippets: Flatten an HTML fragment into a single line for an embed field that rejects line breaks.
- Quick size estimate: Compare the raw and minified character counts to see how much whitespace a file carries.
Frequently Asked Questions
What does each language mode actually remove?
HTML mode deletes comments, removes whitespace next to block-level tags such as div, p and li, and collapses other runs of whitespace to one space, keeping a single space between inline elements and leaving pre, textarea, script and style contents untouched. CSS mode drops comments, removes spaces around braces, semicolons and commas and after the colon in declarations, drops the last semicolon in each rule, and leaves quoted strings and selector spacing such as 'a :hover' alone. JS mode strips comments, removes unnecessary spaces and removes line breaks only where no statement can end.
Is this a full minifier with variable renaming or dead code removal?
No. It removes comments and whitespace only. It does not rename identifiers, drop unused code or rewrite syntax. To keep code that relies on automatic semicolon insertion working, it keeps a line break wherever the previous line could end a statement, so the output of semicolon-free code may still span several lines.
Will a URL or regex containing // be cut off?
No. JS mode reads quoted strings, template literals and regular expression literals as whole tokens before looking for comments, so https://example.com inside a string, a regex such as /\/\//g, or // inside a template literal are kept intact.