Developer Tools
CSS & HTML Minifier
Minify CSS or HTML to shrink file size — strips comments and whitespace and shows how many bytes you saved.
How to use
- 1Choose CSS or HTML and paste the code.
- 2Copy the minified output; the size saving is shown below.
Frequently asked questions
Is minification safe?
Yes for standard code: only comments and unnecessary whitespace are removed. Content inside <pre>, <textarea> and strings is preserved.
How much smaller will files get?
Typically 15–30% for hand-written CSS and HTML. Gzip or Brotli compression on your server saves much more on top.
How do I minify JavaScript?
Use the JavaScript Minifier tool, which safely renames variables and removes dead code.
A hand-rolled minifier, and what it protects to stay safe
This minifier doesn't ship a full CSS or HTML parser — it uses targeted regular expressions, which makes it fast but means it has to explicitly protect content that looks like syntax but isn't. Before stripping anything, the HTML path pulls the full contents of `<pre>`, `<textarea>`, `<script>` and `<style>` blocks out into a side table (swapped back in afterward), and the CSS path does the same for quoted strings — so a `content: " ; "` declaration or a `<pre>` block with deliberate whitespace survives untouched even though whitespace everywhere else gets collapsed. That's also exactly why it can't minify JavaScript here: stripping whitespace from JS can change behavior (automatic semicolon insertion, regex-vs-division ambiguity) in ways CSS and HTML whitespace never does, which is why there's a separate JS Minifier that does real tokenization instead of regex substitution.
What actually gets removed
For CSS: comments, and whitespace around `{ } : ; , > ~ +`, plus a trailing `;` before a closing `}` (both legal to drop). For HTML: comments (except IE conditional comments, which are preserved since removing them silently changes old-browser behavior), and runs of whitespace between tags collapsed to one space or none. Neither path touches the actual values, tags or attributes, so the minified version is byte-for-byte equivalent in rendered output.
Why the savings number matters more than it looks
The before/after byte counts use TextEncoder so multi-byte UTF-8 characters are counted correctly, not just string length. Typical savings for hand-written CSS/HTML run 15–30% here — real but modest compared to what gzip or Brotli compression adds on top at the server level, since compression already eliminates most repeated whitespace. Minifying is still worth doing for files served uncompressed, or simply to strip comments you don't want shipped to users inspecting page source.
Worked example: CSS & HTML Minifier
Feed in `/* c */\na , b > c {\n color : red ;\n content: "a ; b";\n}` and the output is `a,b>c{color:red;content:"a ; b"}` — the comment is gone, selector spacing around `,` and `>` is stripped, and the trailing `;` before `}` is dropped, but the string `"a ; b"` keeps its internal spaces and semicolon exactly, since quoted strings are protected from the whitespace-collapsing pass entirely.
HTML keeps the insides of pre, textarea, script, and style
Language opens on CSS, so a stylesheet is minified without a switch. HTML is the other choice. On HTML, the contents of pre, textarea, script, and style are set aside and put back unchanged, including the spaces inside them. Ordinary comments are removed. A comment that begins like an old conditional comment is kept. On CSS I stay with the default and only switch when the file is a page. I use the HTML choice when a sample in a pre block should keep its line breaks. The menu stays on CSS until I change it.
Related tools
- JavaScript Minifier
Minify JavaScript with Terser — removes whitespace and comments, shortens variable names and drops dead code to cut file size.
- SVG Optimizer (Minify SVG)
Shrink SVG files by removing editor metadata (Inkscape, Illustrator, Sketch), comments and whitespace, and rounding long decimals — with the size saving shown. Paste the SVG code.
- Code Beautifier (HTML, CSS, JavaScript)
Beautify messy or minified HTML, CSS and JavaScript into clean, consistently indented code you can read and edit.
- Online HTML, CSS & JS Editor (Live Preview)
Write HTML, CSS and JavaScript and see the result instantly — live preview, console, templates, shareable links and one-click HTML download. Like CodePen, with nothing to sign up for.
- Compress PDF
Shrink a PDF for email or upload. Pick light (keeps text selectable) or stronger image-based compression.
- Compress Word, Excel & PowerPoint Files
Make .docx, .xlsx and .pptx files small enough to email: pictures are scaled to the size they're shown at and re-compressed, unused pictures and thumbnails are dropped, and the file is re-zipped. Text and layout don't change.