Skip to content

Sass Do's and Don'ts

This lesson pairs common Sass mistakes directly against their recommended fix, side by side, for a fast, scannable reference you can return to while writing or reviewing real Sass code.

Why Side-by-Side Comparisons Help

Seeing the "don't" and the "do" next to each other makes the reasoning concrete and immediately actionable, rather than abstract advice. Each pair below reflects a genuinely common pattern seen in real Sass codebases.

// Don't
@import 'colors';
.btn { color: $primary; }

// Do
@use 'colors';
.btn { color: colors.$primary; }

The "Do" version gains namespacing, single-load guarantees, and future compatibility as @import moves toward removal.

How to Use This Reference

Don't: <problematic pattern>
Do: <recommended alternative>
Why: <the underlying reasoning>
  • Each pair below shows a common problematic pattern next to its fix.
  • The reasoning matters more than memorizing the fix itself, apply the same thinking to new situations.
  • Not every "don't" is strictly wrong in every context, but each has a clearly better default.

Sass Do's and Don'ts Cheatsheet

Quick comparisons across the most common Sass decisions.

Don't Do
@import 'file'; @use 'file';
width: 100% / 3; width: math.div(100%, 3);
Hardcoded hex colors everywhere Centralized color token map
Nesting 5+ levels deep BEM with &, ~3 levels max
Mixin with no parameters for fixed styles Placeholder + @extend
Raw pixel values in media queries Shared breakpoint map + respond-to() mixin
Silent null returned on bad input @error with a clear message

Module System

Don't continue writing new @import statements. Do migrate to @use/@forward, which provide namespacing, single-load guarantees, and private members, none of which @import supports.

Nesting and Selectors

Don't nest five or six levels deep chasing a visual hierarchy match with your HTML. Do use BEM naming combined with &, which keeps selectors flat, low-specificity, and easy to override.

Reuse: Mixins, Functions, and Placeholders

Don't reach for a parameterless mixin purely to avoid retyping a few lines. Do use a placeholder with @extend for fixed, unvarying styles, and reserve mixins for anything that genuinely needs parameters.

Common Mistakes

  • Following a "don't" out of habit long after learning the recommended "do" alternative.
  • Applying a "do" rule too rigidly in a case where the "don't" pattern is actually the more pragmatic choice.
  • Not sharing this kind of reference with newer team members, causing inconsistent patterns across a codebase.
  • Treating these as absolute rules rather than strong defaults that still require judgment for edge cases.

Key Takeaways

  • Side-by-side comparisons make Sass best practices concrete and immediately actionable.
  • Module system, nesting depth, and reuse-tool choice are the areas with the clearest do/don't guidance.
  • These are strong defaults, not absolute laws, use judgment for genuine edge cases.
  • Sharing this kind of reference across a team keeps a codebase consistent as it grows.

Pro Tip

Turn this do's and don'ts list into an actual project-specific style guide document (or a linter configuration where possible), a shared, written reference prevents the same debates from resurfacing in every single code review.