Performance: @extend directive
This affects CSS bundle size and browser rendering performance by duplicating or merging selectors.
.btn-primary, .btn-secondary { color: blue; padding: 1rem; }
.btn-primary { color: blue; padding: 1rem; } .btn-secondary { color: blue; padding: 1rem; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Repeated styles without @extend | No extra DOM operations | 0 | Low | [X] Bad |
| @extend with complex selectors | No extra DOM operations | 0 | Medium due to complex style calculation | [!] OK |
| Manual selector grouping | No extra DOM operations | 0 | Low | [OK] Good |
@extend directive do in Sass?@extend@extend directive is used to share styles between selectors in Sass.@extend does@extend = reuse styles [OK]@extend shares styles between selectors [OK]@extend creates new properties@extend with imports@extend to define variables.button to .submit in Sass?@extend syntax@extend followed by the selector name without quotes or parentheses.@extend .button; which is correct. Others use wrong syntax like parentheses or quotes.@extend .selector; [OK]@extend followed by selector without quotes or parentheses [OK].alert { color: red; font-weight: bold; }
.error { @extend .alert; }@extend output@extend merges selectors so they share the same style block..alert and .error share the same styles in one combined selector.@extend [OK]@extend combines selectors sharing styles [OK].card { border: 1px solid black; }
.panel { @extend card; }@extend selector syntax@extend card; misses the dot, should be @extend .card;.card in @extend selector. -> Option A@extend [OK]@extend [OK]@extend can't be used inside rules.warning style that shares all styles from .alert but also adds background-color: yellow;. Which Sass code correctly does this?@extend usage with additional styles@extend inside a selector and add other properties after it..warning { @extend .alert; background-color: yellow; } correctly uses @extend .alert; then adds background-color in the same block. Others have syntax errors: parentheses after selector, missing dot before alert, or missing semicolon.@extend plus extra styles in same block [OK]@extend first, then add extra styles in same block [OK]@extend@extendPass the test and this pattern moves unknown