What are the pros and cons of CSS preprocessors?
CSSThe short answer
CSS preprocessors like Sass, Less, and Stylus extend CSS with features like variables, nesting, mixins, and functions. They compile down to regular CSS. They make large stylesheets easier to write and maintain, but they add a build step, can lead to overly complex CSS, and many of their features are now available in native CSS.
What preprocessors add
Variables (now available in native CSS too):
// Sass$primary: #3b82f6;$spacing: 16px;.button { background: $primary; padding: $spacing;}Nesting:
.nav { display: flex; .nav-item { padding: 8px; &:hover { background: gray; } }}Mixins — reusable blocks of styles:
@mixin flex-center { display: flex; align-items: center; justify-content: center;}.hero { @include flex-center; height: 100vh;}Functions and math:
@function spacing($multiplier) { @return $multiplier * 8px;}.card { padding: spacing(2); // 16px margin-bottom: spacing(3); // 24px}Pros
- Better organization — nesting mirrors HTML structure
- Reusability — mixins and functions avoid repetition
- Maintainability — variables make it easy to change values in one place
- Partials and imports — split styles into multiple files
Cons
- Build step required — need to compile Sass/Less to CSS
- Debugging complexity — the CSS in the browser does not match the source file
- Nesting abuse — deeply nested selectors produce overly specific CSS
- Learning curve — team members need to learn the preprocessor syntax
- Native CSS catching up — CSS custom properties, nesting, and
@layerreduce the need for preprocessors
Modern alternatives
- CSS custom properties — native variables that work at runtime
- CSS nesting — now supported in modern browsers
- Tailwind CSS — utility-first approach, no preprocessor needed
- CSS Modules — scoped styles without preprocessing
- CSS-in-JS — styled-components, Emotion
Interview Tip
Mention that preprocessors solved real problems (variables, nesting, reuse) but native CSS has caught up with custom properties and nesting. If the interviewer asks what you prefer, have an opinion — "I use Sass for large projects but native CSS is closing the gap" is a reasonable answer.
Why interviewers ask this
This tests if you know the CSS tooling landscape. Interviewers want to see if you have used preprocessors, understand their tradeoffs, and know about modern alternatives. Having a nuanced opinion shows experience.