Sass @else is the fallback block after an @if. This page focuses on the simple two-way pattern @if … @else …: themes, variants, and function returns. Multi-condition @else if chains are covered on a separate page.
01
Fallback
@else
02
Pair
After @if
03
Exclusive
One branch
04
Themes
Light / dark
05
Variants
Primary / ghost
06
Practice
5 examples
Concept
What Is @else?
Official docs: an @if rule can optionally be followed by an @else rule, written @else { … }. This rule’s block is evaluated if the @if expression returns false (more precisely: if it is falsey).
Must come right after an @if (same chain).
Runs only when the preceding @if condition fails.
Exactly one of @if / @else runs in a two-branch pair.
Compile-time only—never appears in the CSS file.
💡
Beginner tip
@if alone can skip styles. Add @else when you need a guaranteed alternate: “if light theme … otherwise dark theme.”
The @else block is attached to the @if with } @else { (same line or next). It is not a second, separate rule floating elsewhere in the file.
Pairing
🤝 How @else Pairs With @if
Review @if for truthiness: only false and null are falsey. When the @if condition is falsey, Sass evaluates the @else block instead.
@if condition
What runs
Truthy
@if block only
Falsey
@else block only
Why @else
⚖️ @else vs a Second @if
Two separate @if blocks can both emit CSS if both conditions pass. An @if / @else pair is mutually exclusive—ideal for opposites like primary vs ghost, filled vs outline, or light vs dark.
styles.scss
// Exclusive: only one branch
@if $primary { … } @else { … }
// Not exclusive: both can run
@if $primary { … }
@if not $primary { … } // easy to drift out of sync
Next steps
📄 What About @else if?
When you need more than two outcomes (up / right / down / left, multiple sizes, and so on), Sass lets you chain @else if conditions before a final @else. That multi-branch pattern has its own tutorial so this page can stay focused on the clear two-way @else fallback.
💡
Scope of this page
Master @if + @else for binary choices first. Continue with the @else if page when you need a longer decision chain.
Use @else when you only need optional extra styles
Duplicate entire mixins for two variants
Hide a long keyword list inside one @else
Expect @else to run in the browser
Mix unrelated concerns in the fallback branch
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Sass @else
The exclusive fallback when an @if condition fails.
5
Core concepts
📝01
@else
fallback block
Branch
🤝02
After @if
same chain
Pair
⚖️03
Exclusive
one side wins
Binary
🎨04
Variants
themes & modes
API
✓05
Compile
CSS from winner
Output
❓ Frequently Asked Questions
An @else block follows an @if and runs only when that @if expression is falsey. It provides the alternate branch of a two-way compile-time choice.
No. @else must immediately follow an @if (or, on another page, an @else if chain). It is not a standalone at-rule.
In a simple @if / @else pair, exactly one block is evaluated: the @if block if the condition is truthy, otherwise the @else block.
No. @else is the final fallback with no extra condition. @else if adds another tested condition and is covered on a separate tutorial page.
No. Like @if, it is compile-time only. Browsers see only the styles from the branch that ran.
Use @else when the two outcomes are mutually exclusive (light vs dark, primary vs ghost). Two separate @if blocks can both run if you are not careful.
Did you know?
Official Sass docs introduce @else right after @if with a theme mixin—because light/dark is the classic mutually exclusive pair where a bare @if is not enough.
@else completes a two-way compile-time choice: when @if fails, the fallback branch runs instead. Use it for exclusive variants and themes; continue with @else if when you need more than two outcomes.