Free tool
HTML and CSS Minifier
Strip comments and extra whitespace from HTML or CSS conservatively, and see the bytes saved.
How it works
What is the HTML and CSS Minifier?
The HTML and CSS Minifier is a free tool that removes comments and unneeded whitespace from HTML or CSS and reports how many bytes that saves. It is deliberately conservative: in HTML mode the contents of pre, script, style and textarea are left untouched, and CSS values and selectors are never rewritten.
How to use the HTML and CSS Minifier
- Choose HTML or CSS.
- Paste your code, or press Load sample.
- For HTML, decide whether to also remove the space between tags.
- Check the bytes saved, then press Copy code.
What does minifying HTML and CSS do?
Minifying removes characters a browser does not need: comments, line breaks, indentation and repeated spaces. The page renders the same and the file is smaller, so it downloads a little faster.
The four figures above the output show the original size, the minified size, the bytes saved and the percentage. Sizes are UTF-8 bytes, which is what is actually sent over the network before compression.
What does the HTML mode remove, and what does it leave alone?
It removes HTML comments and collapses every run of spaces, tabs and line breaks to a single space, both in text and between attributes inside a tag. Attribute values in quotes are not touched.
It leaves alone anything where whitespace or comments can carry meaning: the full contents of pre, script, style and textarea elements, and conditional comments of the <!--[if ...]> kind used for old Outlook and Internet Explorer. Inline scripts and styles are not minified. One limit to know: if you use the CSS property white-space: pre on an ordinary element, its spacing will be collapsed, because the tool cannot see your stylesheet.
Is it safe to remove the space between tags?
Not always, which is why it is a separate option that is off by default. Between block elements such as div and p, whitespace has no visual effect and can go. Between inline elements it is rendered as a space: two links or a word and a span separated by a line break in the source will touch each other if that whitespace is removed.
With the option off, the tool keeps one space wherever there was whitespace, which is always safe. Turn it on for layout-only markup, then check the page.
What does the CSS mode do?
It removes comments, collapses whitespace, and deletes the spaces around braces, semicolons and commas and after colons, plus the last semicolon in each rule. Strings in quotes are protected, so content values and quoted URLs come through unchanged.
It does not shorten colors, merge rules, drop units from zero values or rename anything. Build tools such as cssnano and esbuild do those deeper optimizations and save more. This tool is for a quick, predictable result you can paste straight into a CMS, an email template or a style tag. Spaces before a colon are kept on purpose, because a :hover and a:hover are different selectors.
How much does minification help page speed?
It depends on how much whitespace and commenting the source has, so the honest answer is the percentage shown for your own code. Hand-written, well-indented files shrink noticeably. Code that a build step already minified will not shrink at all.
Also remember that servers normally compress text with gzip or Brotli, which already squeezes repeated whitespace well, so the saving on the wire is smaller than the raw figure. Minify because it is free, not because it will transform your load time. For email templates, run the Email CSS Inliner first, and to turn Markdown into HTML before minifying use the Markdown HTML Converter.
Questions
- Does minifying change how a page looks?
- It should not. The HTML mode keeps one space wherever whitespace existed, unless you choose to remove space between tags, which can close gaps between inline elements.
- Does the tool minify JavaScript?
- No. Script contents are passed through unchanged. Safe JavaScript minification needs a real parser, such as Terser or esbuild.
- Can I undo minification?
- Whitespace can be restored with a formatter, but removed comments are gone. Keep the original source and treat minified code as an output.
- Is minifying the same as compressing?
- No. Minifying edits the code itself. Compression such as gzip or Brotli is applied by the server in transit and reversed by the browser. They work together.
- Is the HTML and CSS Minifier free?
- Yes, with a free spyc.ai account. It runs in your browser, so nothing you type or paste is sent to a server.
Developer Tools
More in Developer Tools
JSON Formatter
Format, minify and validate JSON in your browser, with the line and column of the first syntax error.
Format JSONJSON-LD Formatter
Pretty-print JSON-LD pasted bare or in script tags, list every @type and flag a missing @context.
Format JSON-LDCase Converter
Convert text to upper, lower, title or sentence case, or to camelCase, PascalCase, snake_case and kebab-case.
Convert caseReady when you are
Before your next buyer asks AI about you, ask AI about yourself
One check, four engines, about twenty seconds. We show you the answers before we ask for anything.