Currently, PostCSS has more than 200 plugins
It is recommended by Google and used in Twitter.
Someone asked Andrey: why did you create PostCSS?
Because I sent a pull request to compass CSS and they didn't answered me
Total number of downloads between Jun 06 2015 and Jun 05 2016: 17.428.020
If you can imagin, you can do it
*But there are also plugin packages
Compare CSS processors for parsings, nested rules, mixins, variables and math:
PostCSS: 39 ms
Rework: 73 ms (1.9 times slower)
libsass: 77 ms (1.9 times slower)
Less: 179 ms (4.5 times slower)
Stylus: 269 ms (6.8 times slower)
Stylecow: 271 ms (6.9 times slower)
Ruby Sass: 1101 ms (28.0 times slower)
npm install gulp-postcss --save-dev
npm install postcss-import --save-dev
npm install cssnext --save-dev
npm install postcss-nested --save-dev
npm install postcss-mixins --save-dev
var gulp = require('gulp');
var postcss = require('gulp-postcss');
var import = require('postcss-import');
var cssnext = require('cssnext');
var mixins = require('postcss-mixins');
var nested = require('postcss-nested');
gulp.task('css', function() {
var processors = [
import,
cssnext,
mixins,
nested
];
return gulp.src('./src/*.css')
.pipe(postcss(processors))
.pipe(gulp.dest('./dest'));
});
gulp.task('watch', function() {
gulp.watch('src/**/*.css', ['css']);
});
Add vendor prefixes to CSS rules using values from Can I Use.
:fullscreen a {
display: flex
}
:-webkit-full-screen a {
display: -webkit-box;
display: flex
}
:-moz-full-screen a {
display: flex
}
:-ms-fullscreen a {
display: -ms-flexbox;
display: flex
}
:fullscreen a {
display: -webkit-box;
display: -ms-flexbox;
display: flex
}
Compresses your css
@charset "utf-8";h1:before{margin:10px 20px;color:red;border-radius:16px;font-weight:normal;background-position:100% 100%}
PostCSS plugin to inline @import rules content
@import "helpers/var.css";
PostCSS plugin to unwrap nested rules like how Sass does it.
.phone {
&_title {
width: 500px;
@media (max-width: 500px) {
width: auto;
}
body.is_dark & {
color: white;
}
}
img {
display: block;
}
}
.phone_title {
width: 500px;
}
@media (max-width: 500px) {
.phone_title {
width: auto;
}
}
body.is_dark .phone_title {
color: white;
}
.phone img {
display: block;
}
PostCSS plugin for mixins
@define-mixin icon $network, $color: blue {
.icon.is-$(network) {
color: $color;
@mixin-content;
}
.icon.is-$(network):hover {
color: white;
background: $color;
}
}
@mixin icon twitter {
background: url(twt.png);
}
@mixin icon youtube, red {
background: url(youtube.png);
}
.icon.is-twitter {
color: blue;
background: url(twt.png);
}
.icon.is-twitter:hover {
color: white;
background: blue;
}
.icon.is-youtube {
color: red;
background: url(youtube.png);
}
.icon.is-youtube:hover {
color: white;
background: red;
}
PostCSS plugin to sort rules content with specified order.
Declarations. Example: { "sort-order": [ "margin", "padding" ] }
/* before */
p {
padding: 0;
margin: 0;
}
/* after */
p {
margin: 0;
padding: 0;
}
Grouping. Example: { "sort-order": [ [ "margin", "padding" ], [ "border", "background" ] ] }
/* before */
p {
background: none;
border: 0;
margin: 0;
padding: 0;
}
/* after */
p {
margin: 0;
padding: 0;
border: 0;
background: none;
}
A mighty, modern CSS linter that helps you enforce consistent conventions and avoid errors in your stylesheets.
var()
calc()
color()
function hwb()
function gray()
function #rrggbbaa
colors rgba
function
(rgb
fallback)
rebeccapurple
color font-variant
property filter
property
(svg fallback)
initial
value rem
unit
(px
fallback)
:any-link
pseudo-class :matches
pseudo-class :not
pseudo-class
(to l.3)
::
pseudo syntax
(:
fallback)
overflow-wrap
property
(word-wrap
fallback)
Use Sass-like markup in your CSS
:root{
--color:#f2b806;
}
.foo{
color:var(--color);
}
W3C Editor's Draft
W3C Editor's Draft
@custom-selector :--heading h1, h2, h3, h4, h5, h6;
:--heading { /* styles for all headings */ }
:--heading + p { /* more styles */ }
/* etc */
:root {
--toolbar-theme: {
background-color: hsl(120, 70%, 95%);
border-radius: 4px;
border: 1px solid var(--theme-color late);
};
--toolbar-title-theme: {
color: green;
};
}
.toolbar {
@apply --toolbar-theme;
}
.toolbar > .title {
@apply --toolbar-title-theme;
}
It's possible