Discover how a small Sass trick can save your website from slow loading and messy styles!
Why Avoiding selector bloat from @extend in SASS? - Purpose & Use Cases
Imagine you have many buttons on your website, and you want them all to share the same style. You copy and paste the same CSS rules into each button's style block.
When you want to change the button style, you have to update every single copy. This is slow and easy to forget, causing inconsistent looks and extra work.
Using @extend in Sass lets you write the style once and share it across many selectors. But if used carelessly, it can create very long combined selectors, making your CSS file bigger and slower.
.btn-primary { color: white; background: blue; }
.btn-secondary { color: white; background: blue; }.btn-primary, .btn-secondary { color: white; background: blue; }You can keep your styles DRY (don't repeat yourself) without making your CSS files huge and slow to load.
On a website with many button types, avoiding selector bloat means faster page loads and easier style updates, improving user experience and developer happiness.
Copying styles manually causes extra work and errors.
@extend helps share styles but can create long selectors if overused.
Learning to avoid selector bloat keeps CSS efficient and maintainable.