Sass booleans are true and false. This page covers operators (and / or / not), truthiness, @if, the if() function, and five compiled examples.
01
true / false
Literals
02
Operators
and / or / not
03
@if
Gate styles
04
if()
Pick a value
05
Truthiness
false & null
06
Practice
5 examples
Concept
What Are Sass Booleans?
Official docs: booleans are the logical values true and false. Besides writing them literally, you get them from equality and relational operators, and from many built-in functions such as map.has-key().
Compile-time only—browsers never evaluate Sass boolean logic.
Official docs: and is true when both sides are true; or is true when either side is true; not flips a single boolean. For a deeper operator focus, see Boolean operators.
Expression
Result
true and false
false
true or false
true
not true
false
not false
true
Control
🚀 Using Booleans
Official docs highlight two main tools:
@if — evaluate a block of styles when the condition is truthy.
if() — return one value if the condition is truthy, and another if it is falsey: if($cond, $when-true, $when-false).
Conditions
✅ Truthiness and Falsiness
Official docs: anywhere true or false are allowed, other values work too. Only false and null are falsey. Every other value is truthy—including 0, empty strings, and empty lists.
💡
Heads up
This differs from JavaScript and many other languages. Do not assume empty or zero means “off” in Sass—check explicitly when that matters.
Cheat Sheet
⚡ Quick Reference
Goal
Code
Literals
true / false
Compare
1px == 1px, 10px < 3px
Combine
$a and $b, $a or $b, not $a
Optional styles
@if $flag { … }
Pick a value
if($flag, 10px, 30px)
Falsey values
false, null only
Hands-On
Examples Gallery
Each example shows boolean logic at compile time. Open View Compiled CSS for verified output.
📚 Getting Started
Produce booleans, then use them to gate styles.
Example 1 — Comparisons & and / or / not
Equality, relational checks, and boolean word operators.
Missing keys from map.get are null (falsey), so unset flags stay off. or lets either border or outline enable a border.
Applications
🚀 Real-World Use Cases
Mixin options — $circle, $responsive, $dark.
Feature flags — maps of toggles for component variants.
Validation — @if not list.index(…) before emitting CSS.
Value switching — if($compact, 0.5rem, 1rem).
Guards — skip rules when a token is missing (null).
🧠 How Compilation Works
1
Evaluate the condition
Resolve comparisons, helpers, and and/or/not.
Check
2
Apply truthiness
Treat only false and null as failing conditions.
Truth
3
Choose the branch
Emit an @if block or pick an if() value.
Branch
4
✓
CSS ships
Only the chosen styles remain; boolean logic does not.
Watch Out
⚠️ Common Pitfalls
Assuming 0 is falsey — in Sass it is truthy.
Using && / || / ! — Sass wants and / or / not.
Empty string / empty list as “off” — both are truthy.
Forgetting null from helpers — missing keys/indexes are falsey by design.
Expecting runtime toggles — Sass booleans are compile-time only.
Pro Tips
💡 Best Practices
✅ Do
Name flags clearly ($circle, $dark-mode)
Default optional mixin args to false
Use @if for whole rule blocks
Use if() for single property values
Compare explicitly when zero/empty should mean “off”
❌ Don’t
Copy JavaScript operator symbols into Sass
Treat empty lists or 0 as false
Hide complex conditions without parentheses when clarity suffers
Emit both branches when one flag should exclude the other
Expect CSS to re-evaluate Sass @if later
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Sass booleans
true/false, word operators, and only two falsey values.
5
Core concepts
✅01
true / false
core values
Basics
⚖️02
and / or / not
word ops
Logic
🔄03
@if / if()
gate or pick
Control
🚫04
Falsey
false & null
Truth
✓05
Compile-time
not in CSS
Stage
❓ Frequently Asked Questions
Booleans are the logical values true and false. They come from literals, equality/relational operators, and many built-in functions such as map.has-key().
Use word operators: and (both true), or (either true), and not (opposite). Unlike JavaScript, Sass does not use &&, ||, or !.
Only false and null. Empty strings, empty lists, and the number 0 are all truthy.
Use @if $flag { … } to include a block when the condition is truthy, or if($condition, $if-true, $if-false) to pick one value.
No. Boolean logic and @if run at compile time. Browsers only see the CSS that was emitted.
string.index returns null when a substring is missing (falsey) and a number when found (truthy), so it works directly in @if conditions.
Did you know?
Official Sass docs call out that empty strings, empty lists, and 0 are all truthy—a common surprise for developers coming from JavaScript or PHP.
Sass booleans are simple true / false values with word operators and a strict truthiness rule: only false and null fail. Use them with @if and if() to shape CSS at compile time.