CSS Preprocessors & Tools

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 {
  &amp;: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 autoprefixer

CSSnano

Minifies CSS by removing whitespace, comments, and optimizing code.

npm install cssnano

PostCSS Preset Env

Use future CSS features today with automatic polyfills.

npm install postcss-preset-env

Tailwind CSS

Utility-first CSS framework implemented as PostCSS plugin.

npm install tailwindcss

Setup & 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

1 / 4
1

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.

1 of 4
🔍PostCSS is a Platform
PostCSS itself does almost nothing — it just parses CSS into an AST. All the power comes from plugins. This makes it infinitely extensible: you can write your own plugin to transform CSS in any way you need.

🎯 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 browserslist setting 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.