githubEdit

PostCSS

Philosopher’s stone, logo of PostCSS

PostCSS is a tool for transforming styles with JS plugins. These plugins can lint your CSS, support variables and mixins, transpile future CSS syntax, inline images, and more.

PostCSS is used by industry leaders including Wikipedia, Twitter, Alibaba, and JetBrains. The Autoprefixerarrow-up-right PostCSS plugin is one of the most popular CSS processors.

PostCSS takes a CSS file and provides an API to analyze and modify its rules (by transforming them into an Abstract Syntax Treearrow-up-right). This API can then be used by pluginsarrow-up-right to do a lot of useful things, e.g. to find errors automatically insert vendor prefixes.

Support / Discussion: Gitterarrow-up-right Twitter account: @postcssarrow-up-right VK.com page: postcssarrow-up-right 中文翻译: README-cn.mdarrow-up-right

For PostCSS commercial support (consulting, improving the front-end culture of your company, PostCSS plugins), contact Evil Martiansarrow-up-right at surrender@evilmartians.comenvelope.

Sponsored by Evil Martiansarrow-up-right

Plugins

Currently, PostCSS has more than 200 plugins. You can find all of the plugins in the plugins listarrow-up-right or in the searchable catalogarrow-up-right. Below is a list of our favorite plugins — the best demonstrations of what can be built on top of PostCSS.

If you have any new ideas, PostCSS plugin developmentarrow-up-right is really easy.

Solve Global CSS Problem

Use Future CSS, Today

Better CSS Readability

Images and Fonts

Linters

Other

Syntaxes

PostCSS can transform styles in any syntax, not just CSS. If there is not yet support for your favorite syntax, you can write a parser and/or stringifier to extend PostCSS.

Articles

More articles and videos you can find on awesome-postcssarrow-up-right list.

Books

Usage

You can start using PostCSS in just two steps:

  1. Find and add PostCSS extensions for your build tool.

  2. Select pluginsarrow-up-right and add them to your PostCSS process.

CSS-in-JS

The best way to use PostCSS with CSS-in-JS is astroturfarrow-up-right. Add its loader to your webpack.config.js:

Then create postcss.config.js:

Parcel

Parcelarrow-up-right has built-in PostCSS support. It already uses Autoprefixer and cssnano. If you want to change plugins, create postcss.config.js in project’s root:

Parcel will even automatically install these plugins for you.

Please, be aware of the several issues in Version 1arrow-up-right. Notice, Version 2arrow-up-right may resolve the issues via issue #2157arrow-up-right.

Webpack

Use postcss-loaderarrow-up-right in webpack.config.js:

Then create postcss.config.js:

Gulp

Use gulp-postcssarrow-up-right and gulp-sourcemapsarrow-up-right.

npm run / CLI

To use PostCSS from your command-line interface or with npm scripts there is postcss-cliarrow-up-right.

Browser

If you want to compile CSS string in browser (for instance, in live edit tools like CodePen), just use Browserifyarrow-up-right or webpackarrow-up-right. They will pack PostCSS and plugins files into a single file.

To apply PostCSS plugins to React Inline Styles, JSS, Radium and other CSS-in-JSarrow-up-right, you can use postcss-jsarrow-up-right and transforms style objects.

Runners

JS API

For other environments, you can use the JS API:

Read the PostCSS API documentationarrow-up-right for more details about the JS API.

All PostCSS runners should pass PostCSS Runner Guidelinesarrow-up-right.

Options

Most PostCSS runners accept two parameters:

  • An array of plugins.

  • An object of options.

Common options:

  • syntax: an object providing a syntax parser and a stringifier.

  • parser: a special syntax parser (for example, SCSSarrow-up-right).

  • stringifier: a special syntax output generator (for example, Midasarrow-up-right).

  • from: the input file name (most runners set it automatically).

  • to: the output file name (most runners set it automatically).

Treat Warnings as Errors

In some situations it might be helpful to fail the build on any warning from PostCSS or one of its plugins. This guarantees that no warnings go unnoticed, and helps to avoid bugs. While there is no option to enable treating warnings as errors, it can easily be done by adding postcss-fail-on-warn plugin in the end of PostCSS plugins:

Editors & IDE Integration

VS Code

Atom

Sublime Text

Vim

WebStorm

WebStorm 2016.3 hasarrow-up-right built-in PostCSS support.

Security Contact

To report a security vulnerability, please use the Tidelift security contactarrow-up-right. Tidelift will coordinate the fix and disclosure.

Last updated

Was this helpful?