PostCSS
A tool for transforming CSS with plugins - autoprefixing, future CSS features, and custom transformations.
What is PostCSS?
PostCSS is a tool that transforms CSS with JavaScript plugins. Popular plugins are Autoprefixer (adds vendor prefixes), postcss-preset-env (lets you use future CSS today) and cssnano (minifies). Tailwind CSS also runs as a PostCSS plugin. It sits in your build step, usually configured in postcss.config.js.
// postcss.config.js
module.exports = {
plugins: {
"postcss-preset-env": {},
autoprefixer: {},
cssnano: {},
},
};PostCSS Example
Code Editor
<p>PostCSS runs at build time. You write modern CSS (left), and plugins output CSS for your target browsers (right).</p>
<div class="cols">
<pre>/* you write */
.title {
&:hover { color: red; }
user-select: none;
}</pre>
<pre>/* postcss-preset-env + autoprefixer output */
.title:hover { color: red; }
.title {
-webkit-user-select: none;
user-select: none;
}</pre>
</div>Preview
Popular PostCSS Plugins
Autoprefixer
Automatically adds vendor prefixes based on browser support data.
npm install autoprefixerCSSnano
Minifies CSS by removing whitespace, comments, and optimizing code.
npm install cssnanoPostCSS Preset Env
Use future CSS features today with automatic polyfills.
npm install postcss-preset-envTailwind CSS
Utility-first CSS framework implemented as PostCSS plugin.
npm install tailwindcssSetup & Configuration
Basic Configuration
// postcss.config.js
module.exports = {
plugins: [
require('autoprefixer'),
require('postcss-preset-env')({
stage: 2,
features: {
'nesting-rules': true,
'custom-properties': true
}
}),
require('cssnano')({
preset: 'default'
})
]
}PostCSS — step by step
Install PostCSS and plugins
Add postcss and your chosen plugins via npm. Create a postcss.config.js file and list the plugins in the order you want them to run.
🎯 Quick Check
What PostCSS plugin automatically adds vendor prefixes to your CSS?
PostCSS: summary
Key points
- PostCSS on its own does nothing; every feature comes from a plugin.
- Frameworks like Next.js and Vite run PostCSS automatically when a config file exists.
- Autoprefixer reads your
browserslistsetting to decide which prefixes to add.
Frequently asked questions
›Is PostCSS a preprocessor?
Not exactly. It's a CSS transformation pipeline. It can act like a preprocessor or a postprocessor depending on the plugins you add.