Utvikling · verktøy

CSS-formaterer og minifiserer

Lim inn CSS, og formater den eller bruk den forsiktige minifisereren.

Kjøres i nettleseren. Ingen opplasting.

Values are processed locally in this browser.

Result

—

Om verktøyet

CSS-formaterer og minifiserer sem complicação.

Den lokale formatereren bevarer strenger i anførselstegn og mellomrom i calc(). Den er ikke en fullstendig CSS-parser; sammenlign resultatet før du bruker det i produksjon.

Veiledning

Slik bruker du CSS-formaterer og minifiserer

This page tidies or shrinks a block of CSS. Paste a stylesheet, choose Format to get neat indentation, or choose Minify to remove comments and extra spaces. Formatting is done with the Prettier library and minifying with the csso library, both loaded in your browser. It is not a CSS checker or linter, and it does not fix mistakes, so always compare the result with what you pasted.

Slik gjør du

  1. Paste your CSS into the source box. It must not be empty, and the limit is 200,000 characters.
  2. Pick an action in the list: Format to spread the rules over lines, or Minify to make them as short as the tool can.
  3. Press Calculate. The result appears in the result area. If the CSS has a syntax error, an error message is shown instead of a result.
  4. Press Copy result to put the output on your clipboard, or Clear to empty both boxes and set the action back to Format.

Eksempler

Formatting a compressed rule

Du skriver inn
Handling
Format
CSS
a{color:red;margin:0 auto}.b>p{padding:4px 8px}
Du får
CSS
a { color: red; margin: 0 auto; } .b > p { padding: 4px 8px; }

Each rule gets its own braces, each declaration gets its own line with two spaces of indent, and spaces are added around the child selector sign. The tool wraps lines at 100 characters.

Kjørt med verktøyets egen kode.

Minifying with a comment

Du skriver inn
Handling
Minify
CSS
/* note */ .card { color : #FF0000 ; margin: 0px 0px; width: calc( 100% - 2rem ); }
Du får
CSS
.card{color:red;margin:0 0;width:calc(100% - 2rem)}

The comment and the whitespace are gone. The minifier also rewrote #FF0000 as red and 0px as 0, so its output is more than a space remover. The spacing inside calc stays correct.

Kjørt med verktøyets egen kode.

Broken CSS

Du skriver inn
Handling
Format
CSS
a{color:red
Du får
Feil
CssSyntaxError: Unclosed block (1:1)

The block is never closed, so the formatter stops and shows an error whose first line is this message. It does not guess where the missing brace belongs.

Kjørt med verktøyets egen kode.

Når det er nyttig

  • Make a minified stylesheet readable so you can find a rule.
  • Tidy copied snippets so they match one indentation style before you commit them.
  • Shrink a small stylesheet for a quick test of how much space it can save.
  • Spot a missing brace, since broken CSS makes the formatter report an error.

Begrensninger

  • The input is limited to 200,000 characters, and an empty box is refused.
  • Minify can change values as well as spaces, for example #FF0000 to red and 0px to 0. It also keeps rules in their order and does not merge repeated selectors.
  • Minify can return nothing for nested CSS. In a test, .a{.b{color:red}} came back as an empty result, so compare the output before using it.
  • The result is not a check that the CSS works. The tool does not test colours, property names or how a page looks.

Tips

  • Run Format first on code you do not know. Its readable layout shows mistakes that a single long line hides.
  • Keep your original file when you minify. Minified code is hard to edit by hand.
  • If the minified result looks too short, look for nested rules or unusual syntax in what you pasted.

Vanlige spørsmål

Sobre CSS-formaterer og minifiserer.

What is the difference between Format and Minify?

Format adds line breaks and indentation so people can read the CSS. Minify does the opposite: it removes comments and spaces and shortens some values so the file is smaller. Both aim to keep the styling the same, but you should still test the result.

Does the tool fix errors in my CSS?

No. If the code cannot be read, for example because a brace is missing, it shows an error message and no result. It does not repair the problem, rename properties or check whether a value is valid.

Does it keep text inside quotes and calc spacing?

In the tests run for this page, a quoted string such as content with two spaces inside stayed unchanged when formatting and minifying, and the spaces around the minus in calc were kept. Still, compare the output with your source.

Will it handle SCSS or nested CSS?

It is built for plain CSS. Formatting accepted a nested rule and a simple Sass variable in testing, but minifying dropped the nested rule. Treat SCSS or Less as unsupported and test any other syntax first.

Is my CSS sent to a server?

No. The formatter and the minifier run in your browser, and your code is not uploaded. The page needs to load the Prettier and csso code the first time you press Calculate.

How large can the CSS be?

Up to 200,000 characters in the box. If the text is longer, the tool asks for a shorter source. For very large files, split the CSS into parts and process each one.

Hvordan bruker du CSS-formaterer?

Lim inn CSS, og formater den eller bruk den forsiktige minifisereren.

Lastes dataene mine opp til en server?

Nei. Behandlingen skjer i nettleseren din, og opplysningene dine lastes ikke opp.