Sass boolean operators use words—not symbols—for logic: not, and, and or. This page covers truthiness, how null behaves, combining conditions in @if, and five compiled examples.
01
Operators
notandor
02
Returns
true / false
03
Falsey
false & null
04
Truthy
0, "", lists
05
Use
@if guards
06
Practice
5 examples
Concept
What Are Boolean Operators?
Official docs: unlike languages like JavaScript, Sass uses words rather than symbols for its boolean operators.
not flips a value: true ↔ false.
and needs both sides truthy.
or needs at least one side truthy.
Logic runs when Sass compiles—not in the browser.
Most often used inside @if, mixins, and helpers.
💡
Beginner tip
Read conditions out loud: “if dark andnot compact” becomes @if $dark and not $compact. Sass chooses the branch before CSS is written.
Foundation
📝 Syntax
styles.scss
not $expression
$expression-a and $expression-b
$expression-a or $expression-b
Operators
Operator
Name
Returns
not
negation
Opposite of the expression’s value
and
conjunction
true if both sides are truthy; otherwise false
or
disjunction
true if either side is truthy; otherwise false
Official samples
Expression
Result
not true
false
not false
true
true and true
true
true and false
false
true or false
true
false or false
false
vs JavaScript symbols
Idea
JavaScript
Sass
Negate
!
not
Both true
&&
and
Either true
||
or
Rules
⚖️ Truthiness and Falsiness
Official docs: anywhere true or false are allowed, you can use other values as well.
Falsey — only false and null.
Truthy — every other value, including 0, "", and empty lists.
Value
In a condition
true
Truthy
false
Falsey
null
Falsey
0
Truthy
"" (empty string)
Truthy
() (empty list)
Truthy
⚠️
Heads up
Official docs: some languages treat more values as falsey. Sass is not one of them. Empty strings, empty lists, and 0 are all truthy.
Pattern
🔎 Null Checks & string.index
Official docs: to check if a string contains a space, write string.index($string, " "). The function returns null if the substring is missing and a number otherwise—so it works as a condition directly.
styles.scss
@use "sass:string";
$string: "Hello World";
@if string.index($string, " ") {
// Found a space (number is truthy)
} @else {
// Missing → null is falsey
}
Combine
🔁 Mixing With Comparisons
Boolean operators often wrap equality or relational checks:
styles.scss
@if $width >= 600px and $theme == "dark" {
// wide + dark
}
@if not ($mode == "print") {
// everything except print
}
@if $flag or $fallback {
// use a default when $flag is false/null
}
Parentheses help when you negate a whole comparison: not ($mode == "print").
Cheat Sheet
⚡ Quick Reference
Goal
Code
Negate
not $flag
Both required
$a and $b
Either allowed
$a or $b
Branch
@if $dark and not $compact { ... }
Substring exists
@if string.index($s, " ") { ... }
Explicit null test
$value != null
Inspect a boolean
meta.inspect($a and $b)
Hands-On
Examples Gallery
Each example uses boolean operators at compile time. Open View Compiled CSS for verified output (booleans shown with meta.inspect).
📚 Getting Started
Official not, and, and or samples.
Example 1 — Basic Boolean Ops
Flip values and combine plain true / false.
styles.scss
@use "sass:meta";
.ops {
--not-t: #{meta.inspect(not true)};
--not-f: #{meta.inspect(not false)};
--and-tt: #{meta.inspect(true and true)};
--and-tf: #{meta.inspect(true and false)};
--or-tf: #{meta.inspect(true or false)};
--or-ff: #{meta.inspect(false or false)};
}
Sass boolean operators not, and, and or give you clear compile-time logic. Remember the tiny falsey set (false and null), then drive @if branches with confidence.