0
0
SASSmarkup~3 mins

Why Avoiding selector bloat from @extend in SASS? - Purpose & Use Cases

Choose your learning style9 modes available
The Big Idea

Discover how a small Sass trick can save your website from slow loading and messy styles!

The Scenario

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.

The Problem

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.

The Solution

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.

Before vs After
Before
.btn-primary { color: white; background: blue; }
.btn-secondary { color: white; background: blue; }
After
.btn-primary, .btn-secondary { color: white; background: blue; }
What It Enables

You can keep your styles DRY (don't repeat yourself) without making your CSS files huge and slow to load.

Real Life Example

On a website with many button types, avoiding selector bloat means faster page loads and easier style updates, improving user experience and developer happiness.

Key Takeaways

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.