Description #
PostCSS is a tool for transforming CSS with JavaScript plugins. It enables powerful features like autoprefixing, nesting, linting, and custom syntax extensions to modernize and streamline CSS development.
History #
PostCSS was created by Andrey Sitnik in 2013 and quickly gained popularity for its modular, plugin-driven architecture. It became the foundation for tools like Autoprefixer and frameworks like Tailwind CSS.
Hello World Code #
/* input.css */
:root {
--main-color: hotpink;
}
h1 {
color: var(--main-color);
}
Using a PostCSS plugin (e.g., Autoprefixer), it compiles to:
h1 {
color: hotpink;
}
How to Run #
Option 1: Online
Try the PostCSS Playground:
https://postcss.org/play
Option 2: Local
Install via npm:
npm install postcss autoprefixer
Basic usage:
const postcss = require('postcss')
const autoprefixer = require('autoprefixer')
const fs = require('fs')
const css = fs.readFileSync('input.css', 'utf8')
postcss([autoprefixer])
.process(css, { from: 'input.css', to: 'output.css' })
.then(result => fs.writeFileSync('output.css', result.css))
Key Concepts #
- Plugin-based CSS transformer
- Enables custom syntax and modern features
- Plugins like Autoprefixer, cssnano, postcss-nested
- Doesn’t enforce a specific syntax or style
- Supports SCSS-like features via plugins
- Used in frameworks like Tailwind CSS and Parcel
- Easy integration with Webpack, Rollup, Vite
- Enables CSS linting, minifying, and compiling
- Great for writing future-proof CSS
- Widely supported in modern frontend pipelines
Try It Online #
Fun Facts #
- PostCSS isn’t a CSS preprocessor — it’s a postprocessor, meaning it works after CSS is written.
- Tailwind CSS’s build engine uses PostCSS under the hood.
- Its modular plugin system allows developers to build their own CSS tools with ease.
Resources #
Official site
Docs or tutorial
GitHub or interpreter
Community or learning resources