Performance: Avoiding selector bloat from @extend
This affects CSS file size and browser rendering speed by controlling how many selectors are generated and matched.
Jump into concepts and practice - no test required
@mixin button-style { padding: 1rem; border-radius: 0.5rem; } .button { @include button-style; } .alert { @include button-style; } .card { @include button-style; }
@extend .button; @extend .alert; @extend .card;
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Multiple @extend on different selectors | No direct DOM changes | 0 | High due to complex selector matching | [X] Bad |
| Using mixins for style reuse | No direct DOM changes | 0 | Low due to simple selectors | [OK] Good |
@extend in Sass without placeholders?@extend does@extend shares styles by combining selectors in the output CSS.%btn { color: red; }
.primary { @extend %btn; }
.secondary { @extend %btn; }@extend without placeholders?.btn { color: green; }
.primary { @extend .btn; }
.secondary { @extend .btn; }@extend. Which approach is best?