Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

PostCSS & Autoprefixer | CSS Basics to Advanced lesson | BraveProgrammer
  1. Courses
  2. /
  3. CSS Basics to Advanced

Lesson 41 of 50

·css

PostCSS & Autoprefixer

7 mins

Course progress82%

What you'll learn

Keep these ideas in mind as you work through the lesson.

3 points
  • Run PostCSS as part of your build pipeline (`npm run build`).
  • Keep the **browserslist** file updated to target the browsers you support.
  • You can also use PostCSS for **CSS minification** (`cssnano`).

PostCSS is a plug‑in ecosystem that transforms CSS with JavaScript. It powers Autoprefixer, cssnano, and future‑syntax polyfills.

Autoprefixer – Vendor Prefix Automation

/* input */
.flex { display:flex; }
# after autoprefixer (via postcss-cli)
.flex { display:-webkit-box; display:-ms-flexbox; display:flex; }

Installing & Configuring

npm install postcss postcss-cli autoprefixer postcss-preset-env --save-dev

Create postcss.config.js:

module.exports = {
  plugins: {
    autoprefixer: {},
    'postcss-preset-env': { stage: 1 }, // enables future CSS (e.g., nesting)
    cssnano: { preset: 'default' } // minify for production
  }
};

Run via npm script:

"scripts": { "build:css": "postcss src/*.css -d dist/" }

postcss-preset-env

Allows you to write future CSS now, like :focus-visible or color-mod(), and have it transpiled for older browsers based on your browserslist configuration.

Example – Using CSS Nesting (future syntax)

/* src/components.css */
.card {
  padding:1rem;
  .title { font-size:1.25rem; }
  &:hover { background:#f0f0f0; }
}

After postcss-preset-env →

.card { padding:1rem; }
.card .title { font-size:1.25rem; }
.card:hover { background:#f0f0f0; }

Browserlist Integration

Create a .browserslistrc file:

> 0.5%
last 2 versions
not dead

PostCSS (and Autoprefixer) read this file to know which prefixes to generate.

Pro Tip – Combine with Stylelint

Run linting before PostCSS so you catch errors early:

"scripts": { "lint:css": "stylelint "src/**/*.css"", "build:css": "npm run lint:css && postcss src/*.css -d dist/" }

Performance Note

cssnano minifies the final bundle, removing comments, whitespace, and redundant rules – essential for production.

Accessibility Insight

Autoprefixer does not add accessibility‑related properties, so you must still ensure things like focus-visible are present.

Make it stickPractice what you've learned1 quiz · 6 practical tests · Optional activities from CSS Basics to AdvancedBrowse activities
Previous lessonCSS Pre‑processors – Sass & LessContinue to lesson 42CSS Modules (Scoped CSS)Back to CSS Basics to Advanced curriculum