-
Notifications
You must be signed in to change notification settings - Fork 13
Home
A CSS minifier of PostCSS, by PostCSS, for PostCSS
Also see /test/
directory.
Minify or remove white spaces as possible.
.foo,
.bar {
display : block ;
}
.baz + .qux {
display: block !important;
background-image: url( "baz.png" );
}
becomes:
.foo,.bar{display:block}.baz+.qux{display:block!important;background-image:url(baz.png)}
Remove comments except /*! ... */
.
/* This comment will be removed. */
/*! This comment will NOT be removed. */
becomes:
/*! This comment will NOT be removed. */
Don't touch content
property value.
.foo::before {
content: " Lorem ipsum dolor sit amet. ";
}
becomes:
.foo::before{content:" Lorem ipsum dolor sit amet. "}
Unquote font-family
values as possible.
.foo {
font-family: "Helvetica Neue", "Arial", "Font 01", sans-serif;
}
becomes:
.foo{font-family:Helvetica Neue,Arial,"Font 01",sans-serif}
Omit leading zeros in number.
.foo {
top: 00102px;
}
becomes:
.foo {
top: 102px;
}
Omit unit if value is 0.
.foo {
margin: 0px;
}
becomes:
.foo{margin:0}
Shorten unit if value is 0.
.foo {
transition-duration: 0ms;
}
becomes:
.foo{transition-duration:0s}
Omit leading and trailing zeros from decimal number.
.foo {
font-size: 01.8750em;
}
becomes:
.foo{font-size:1.875em}
Convert colors to its shortest form.
.foo {
border-color: #f00;
color: rgb(36, 36, 36);
background-color: hsl(0, 0%, 93.5%);
outline-color: rgba(0, 0, 0, 0);
}
becomes:
.foo{border-color:red;color:#242424;background-color:#eee;outline-color:transparent}
Unquote inside url()
notation if possible. If not possible, keep original style of quotation mark.
.foo {
background-image: url("foo.png");
list-style-image: url("/~john/foo.png");
cursor: url('/~john/foo.cur');
}
becomes:
.foo{background-image:url(foo.png);list-style-image:url("/~john/foo.png");cursor:url('/~john/foo.cur')}
Gather zeros into one zero.
.foo {
margin: 0 0 0 0;
}
becomes:
.foo{margin:0}
Gather values as possible.
.foo {
margin: 1px 2px 3px 2px;
padding: 1px 2px 1px 2px;
border-color: #000 #000 #000 #000;
}
becomes:
.foo{margin:1px 2px 3px;padding:1px 2px;border-color:#000}
Replace normal
and bold
in font-weight
with 400
and 700
.
.foo {
font-weight: normal;
}
.bar {
font-weight: bold;
}
becomes:
.foo{font-weight:400}.bar{font-weight:700}
Convert to shorter unit if possible.
.foo {
pitch: 48000Hz;
transform-duration: 1000ms;
translate-function: rotate(100grad);
}
becomes:
.foo{pitch:48kHz;transition-duration:1s;transition-timing-function:rotate(90deg)}
Omit semicolon of last declaration in ruleset.
.foo {
margin: 0;
padding: 0;
}
becomes:
.foo{margin:0;padding:0}
Remove empty ruleset.
.foo {
}
.bar {
display: block;
}
becomes:
.bar{display:block}
Remove rulesets with empty selector.
{
display: block;
}
.foo {
display: block;
}
becomes:
.foo{display:block}
Remove invalid keyframe selector.
@keyframes foo {
to {
top: 100px;
}
bar, 50% {
top: 50px;
}
-25% {
top: 999px;
}
}
becomes:
@keyframes foo{to{top:100px}50%{top:50px}}
Remove duplicate selectors.
.foo,
.bar,
.foo {
display: block;
}
becomes:
.bar,.foo{display:block}
Remove duplicate declarations.
.foo {
color: rgb(255, 255, 255);
color: #ffffff;
color: rgba(255, 255, 255, 0);
}
becomes:
.foo{color:#fff;color:rgba(255,255,255,0)}
Remove unnecessary colon from some pseudo elements (::before
, ::after
, ::first-line
, and ::first-letter
).
.foo::before {
color: black;
}
becomes:
.foo:before{color:black}
Remove a declaration that has erroneous property.
.foo {
--Custom: black;
color: black;
col!or: red;
}
becomes:
.foo{--Custom:black;color:black}
Remove all invalid @import
rules.
@import "foo.css";
@import "bar.css";
.baz {
display: block
}
@import "qux.css";
becomes:
@import"foo.css";@import"bar.css";.baz{display:block}
Keep first valid @charset
only, remove rest.
@charset "UTF-8";
.foo {
display: block;
}
@charset "UTF-8";
.bar {
display: block;
}
becomes:
@charset "UTF-8";.foo{display:block}.bar{display:block}
Omit last semicolon of last declaration in at-rule block (such as @font-face
).
@font-face {
font-family: "Foo";
src: url("foo.woff") format("woff");
}
becomes:
@font-face{font-family:Foo;src:url("foo.woff") format("woff")}
Remove @font-face
block without required descriptors (both src
and font-family
).
@font-face {
font-family: "Foo";
src: url("foo.woff") format("woff");
}
@font-face {
font-family: "Bar";
font-weight: 400;
}
@font-face {
src: url("baz.woff") format("woff");
font-weight: 400;
}
becomes:
@font-face{font-family:Foo;src:url(foo.woff) format("woff")}
Remove @font-face
descriptor with default value.
@font-face {
font-family: "Foo";
font-style: normal;
font-weight: 400;
src: url("foo.woff") format("woff");
}
becomes:
@font-face{font-family:Foo;src:url(foo.woff) format("woff")}
Remove all empty at-rule block.
.foo {
display: block;
}
@media (min-width:99px) {
.foo {}
}
@page :left {
}
becomes:
.foo{display:block}
Use quoted string instead of url()
notation in @import
.
@import url("foo.css");
@import url(bar.css);
becomes:
@import"foo.css";@import"bar.css"
Use quoted string instead of url()
notation in @namespace
.
@namespace url("foo.css");
@namespace bar url(bar.css);
becomes:
@namespace"foo.css";@namespace bar"bar.css"
Unquote animation name in @keyframes
.
@keyframes "foo" {
from {
top: 0px;
}
to {
top: 100px;
}
}
becomes:
@keyframes foo{from{top:0}to{top:100px}}