Skip to content

CSS Minifier

Remove CSS comments and extra spaces. A rule a { color: red; } becomes a{color:red;}. The page does not check that the CSS is valid.

Result

Paste CSS

How to Use

  1. 1 Paste up to 20000 characters.
  2. 2 Choose Minify CSS.
  3. 3 a { color: red; } becomes a{color:red;}.

Example Output

  • a { color: red; } becomes a{color:red;}.

About This Tool

Comments inside /* and */ are removed when they are outside quotes. Spaces around braces, colons, and semicolons are removed.

Minifying a { color: red; }

Paste the rule a, then a space, an opening brace, a line break, two spaces, color, a colon, a space, red, a semicolon, a line break, and a closing brace. The field starts with that rule. The headline reads Minified CSS. The label above the headline reads CSS. The result text is a{color:red;}. The labeled line is Characters 13, which is the length of that minified text. The page removed the line breaks and the spaces around the brace, the colon, and the semicolon. It kept the letters. The steps are remove comments outside quotes, remove spaces around braces, colons, and semicolons, and keep text inside quotes.

Comments written with a slash and a star, outside quotes, are removed, including the text inside them. A comment after the sample rule does not change the result. The text is still a{color:red;}, and Characters is still 13. A paste that is only a comment is refused with Enter CSS that still has a rule after comments are removed. The page does not check that the CSS is valid. a{color:red;} is shorter text, not a certificate that a browser will accept the rule. The button says Minify CSS. Before you submit, the waiting line is Paste CSS.

The paste must be from 1 to 20000 characters. Empty text, or text longer than 20000 characters, is refused with Enter from 1 to 20000 characters. That check happens before minifying. Reset restores the sample rule with its line breaks. Copy result copies a{color:red;}. The page does not write a stylesheet, attach the rule to an element, or fetch a file. It rewrites the characters in the box.

Spaces that sit between tokens, rather than beside a brace, a colon, a semicolon, or a comma, can remain as a single space. margin, a colon, a space, 1px, a space, 2px, and a semicolon becomes margin:1px 2px;, and Characters is 15. The space between 1px and 2px stays because both neighbors are letters or digits, not the marks the page squeezes. Text inside quotes stays as typed, spaces included. a { content: "a { b }"; } becomes a{content:"a { b }";}. The braces inside the quotes are characters, not structure the page removes.

What Minifying Changes

Minifying on this page is a character rewrite. Comments outside quotes come out. A run of whitespace shrinks. If the whitespace sits beside a brace, a colon, a semicolon, or a comma, it goes away. If it sits between two tokens that are not those marks, one space remains. Quotes are a protected stretch. From the opening quote to the closing quote, characters are copied, including spaces, braces, and comment marks. A backslash inside a quote keeps the next character with it. The page does not rename selectors, shorten colors, or merge rules.

The headline is always the words Minified CSS on a successful run. The useful text is the rewritten CSS, and the Characters line is how long that text is. For the sample, the text is a{color:red;} and the line is 13. If you paste a{color:red;} already squeezed, the text stays a{color:red;} and Characters stays 13. The page does not report how many characters it removed. You can compare the field with the result if you want that difference. It also does not report whether the rule is valid CSS. The about line says comments inside slash-star marks are removed when they are outside quotes, and spaces around braces, colons, and semicolons are removed. That is the rewrite.

How the Sample Becomes a{color:red;}

The sample is the selector a, a brace, the declaration color, a colon, the value red, a semicolon, and a closing brace, with line breaks and spaces in between. The page walks the characters. The letter a is kept. The space before the brace is dropped because it sits against the brace. The brace is kept. The indent spaces are dropped. color is kept. The colon drops the space after it. red is kept. The semicolon drops the space around the following brace. The closing brace is kept. Nothing in that walk was a comment, and nothing was inside quotes, so the result is a{color:red;}. Count those characters: they are 13, which is the Characters line.

A grid declaration is a different CSS string, built from counts you choose. The CSS Grid Generator builds a grid container with equal columns. 3 columns and a gap of 16 becomes repeat(3, 1fr) and gap 16px. The text sets display to grid, repeats 1fr once per column, and sets the gap in pixels. The page does not write a stylesheet. It does not take a rule like a { color: red; } and squeeze it. Use the grid generator when you want that three-column declaration. Use this page when you already have a rule and you want a{color:red;}.

CSS the Minifier Will Not Check

The page will not open a stylesheet on a server, apply the rule to a page, or tell you that color is a known property. If you paste words that are not CSS, and something remains after comments are removed, the page still returns that remainder with spaces squeezed. That is not a validity check. The refusal Enter CSS that still has a rule after comments are removed appears when the remainder is empty, which is what a comment-only paste produces. The message says rule. The check itself is that the trimmed result is not empty.

A paste over 20000 characters is refused with Enter from 1 to 20000 characters before any rewrite. Shorten it. An empty box gets the same message. An unclosed comment, one that starts with slash-star and never closes, is removed through the end of the paste, because the page looks for the closing star-slash and, failing that, skips the rest. If that skip leaves nothing, you get the empty-result refusal. If it leaves the rule that sat before the comment, you get that rule, minified. The page does not repair a missing closing comment mark. It also does not add braces you forgot.

Rewrites You Can Recompute

Minify the sample and confirm the text a{color:red;} and Characters 13. Paste the same text with a comment after it, slash-star note star-slash. The comment disappears and the text is still a{color:red;}. Paste only the comment and confirm Enter CSS that still has a rule after comments are removed. Paste margin: 1px 2px; and confirm margin:1px 2px; with Characters 15. The space between the two lengths stays. Paste a { content: "a { b }"; } and confirm a{content:"a { b }";}. The spaces and braces inside the quotes stay. Paste a{color:red;} with no extra spaces and confirm it is unchanged, still 13 characters. Clear the box and confirm Enter from 1 to 20000 characters.

A flex container is built from choices, not squeezed from a paste. The CSS Flexbox Generator builds a flex declaration. Row, flex-start, stretch, and a gap of 16 become display flex, flex-direction row, justify-content flex-start, align-items stretch, and gap 16px, each on its own line. Gap must be a whole number from 0 to 100. The page does not write a stylesheet, and it does not remove comments from a rule you already wrote. Use it when you want that flex block. Use this page when the input is the color rule and the output is a{color:red;}.

Limits of the Rewrite

The rewrite does not validate CSS. A missing brace can survive as text. An unknown property can survive as text. A comment inside quotes survives on purpose, because quotes are copied. A comment outside quotes does not survive. The page does not understand a regular expression, a preprocessor variable, or a nested rule beyond the characters it sees. It does not convert a long color to a short color. It does not remove a trailing semicolon. The sample keeps the semicolon in a{color:red;}.

Whitespace rules are local. One space remains between tokens when dropping the space would glue words that are not separated by a brace, colon, semicolon, or comma. That is why 1px 2px keeps its space. Spaces at the very ends of the result are trimmed. The Characters line counts the result, not the input. A 13 on the sample is the length of a{color:red;}, not the length of the rule with its line breaks. The page does not show both lengths. The 20000 character cap applies to the input. A result can be shorter. It is not checked against a second cap of its own, aside from being non-empty after the rewrite.

Mistakes That Miss a{color:red;}

The common miss is to expect a validity verdict. The page does not check that the CSS is valid. Another miss is to expect a comment inside quotes to vanish. a { content: "a { b }"; } keeps the quoted text, including the inner braces and spaces. Another miss is to expect every space to vanish. margin:1px 2px; still has a space between the lengths. Another miss is to treat a comment-only paste as an empty string result. It is refused, with Enter CSS that still has a rule after comments are removed. Another miss is to read Characters 13 as the size of the original field. It is the size of a{color:red;}. A fifth miss is to expect the page to write the result into a stylesheet. It leaves the text in the result panel for you to copy.

A shadow declaration is built from numbers and a color, not from this rewrite. The CSS Box Shadow Generator builds one box-shadow from offsets, a blur, a spread, and a color. 4, 8, 16, 0, and #000000 becomes box-shadow: 4px 8px 16px 0px #000000;. The page does not apply it to a stylesheet. Blur and spread may not be negative. Use it when you want that declaration composed. Use this page when you already wrote a { color: red; } and you want the spaces and the line breaks taken out.

Using the Minified Rule

Paste the CSS you mean to shorten, press Minify CSS, and read the result text before you copy it. For the sample, confirm a{color:red;} and Characters 13. If the result is shorter than you expected, look for a comment that sat outside quotes. That comment is gone. If a space you needed is gone, look for a brace, a colon, a semicolon, or a comma beside it. Those marks lose their neighboring spaces. If a space you hoped would vanish is still there, it likely separates two tokens, as in 1px 2px. Quotes are the place to look when text survived unchanged.

Reading a{color:red;} and 13

Read the sample in this order. The headline is Minified CSS. The label is CSS. The text is a{color:red;}. The line is Characters 13. The steps are remove comments outside quotes, remove spaces around braces, colons, and semicolons, and keep text inside quotes. A refusal is not a character count of 0. Enter from 1 to 20000 characters and Enter CSS that still has a rule after comments are removed mean there is no minified text to record. Write the error, fix the paste, and minify again. Copy result copies a{color:red;}. The Characters line is separate, so write 13 beside the text if the length is part of your note.

Shortening an HTML fragment is a different rewrite. The HTML Minifier removes extra spaces from a fragment. A p element, a line break, Hi, and a closing p becomes <p>Hi</p>. Comments are removed. A script and a document type are rejected. The page does not fetch a page. It does not squeeze a { color: red; } into a{color:red;}. Use it when the paste is HTML. Use this page when the paste is the color rule and the record you want is a{color:red;} at 13 characters.

What the Rewrite Does Not Decide

The minified text does not decide that the rule is correct, small enough, or ready to publish. It decides how this page removed comments outside quotes and extra spaces. You chose the paste. The page kept quoted text, dropped the sample line breaks, and produced a{color:red;}. If you paste a different rule, you get a different string. If you paste a comment only, you get a refusal rather than a blank success. The page cannot know which spacing you still needed between tokens.

Checks on the Sample Rule

Minify the sample and confirm a{color:red;} and Characters 13. Add a comment outside quotes and confirm the comment is gone and the text is unchanged. Paste only a comment and confirm Enter CSS that still has a rule after comments are removed. Paste margin: 1px 2px; and confirm the space between 1px and 2px remains. Paste a quoted content value that includes braces and spaces, and confirm those characters remain inside the quotes. Clear the field and confirm Enter from 1 to 20000 characters. Reset and minify once more so a{color:red;} is the last text.

Shortening a script is a different walk. The JavaScript Minifier removes JavaScript comments and extra spaces outside strings. function a() { return 1; } on several lines becomes function a(){ return 1;}. Text inside quotes stays. The page does not run the script, and a comment mark inside a regular expression can be left as typed. It does not turn a { color: red; } into a{color:red;}. Use it when the paste is JavaScript. Use this page when the paste is CSS and the result you want is the 13-character rule.

Frequently Asked Questions

What does a { color: red; } become?

a{color:red;}. The headline is Minified CSS, and Characters is 13. Spaces and line breaks around the braces, the colon, and the semicolon are removed.

Are comments removed?

Comments outside quotes are removed. A comment after the sample rule leaves a{color:red;}. A comment inside quotes is kept. A paste that is only a comment is refused.

Does the page check that the CSS is valid?

No. It rewrites characters. A successful result is shorter or equal text, not a verdict that a browser will accept the rule.

Why does 1px 2px keep a space?

Spaces beside braces, colons, semicolons, and commas are removed. A space between two tokens, such as the space in margin:1px 2px;, stays. Characters for that string is 15.

What happens inside quotes?

Text inside quotes is kept, including spaces and braces. a { content: "a { b }"; } becomes a{content:"a { b }";}. Comment marks inside those quotes stay as well.

What if the paste is empty or only a comment?

Empty or overlong text is refused with Enter from 1 to 20000 characters. A comment that leaves nothing is refused with Enter CSS that still has a rule after comments are removed.

Does an already short rule change?

a{color:red;} stays a{color:red;}, and Characters stays 13. The page does not report how many characters it removed from a longer paste.

Does the page write a stylesheet?

No. Copy result copies the minified text, such as a{color:red;}. Reset restores the sample rule with its line breaks. The page does not attach the rule to an element.