Sass null means a value is missing. This page covers where null comes from, how it is omitted from CSS, why it is falsey, optional mixin APIs, and five compiled examples.
01
Absence
null
02
Omit list
Drop from CSS
03
Omit prop
Skip property
04
Falsey
@if / if()
05
APIs
Optional args
06
Practice
5 examples
Concept
What Is null?
Official docs: the value null is the only value of its type. It represents the absence of a value, and is often returned by functions to indicate the lack of a result.
Common sources: missing map keys, missing substrings, no parent selector (& at root).
In a CSS list, null items are dropped.
As a property value, null removes that property entirely.
It is falsey—same idea as false in conditions.
💡
Beginner tip
Think of null as “leave this out.” That is why optional mixin parameters often default to null instead of an empty string.
Foundation
📝 Syntax
styles.scss
$missing: null;
$maybe-family: map.get($fonts, "sans"); // null if key missing
.button {
border-radius: $radius; // omitted from CSS when $radius is null
}
Sources
🔍 Where null Comes From
Expression
When it is null
string.index($s, $sub)
Substring not found
map.get($map, $key)
Key not in the map
& (parent selector)
Used at the stylesheet root
list.index($list, $val)
Value not in the list
CSS Output
🗑️ How null Affects CSS
Official docs describe two important behaviors:
In a list — a null entry is omitted. Example: font: 18px bold null becomes font: 18px bold;.
As a property value — the whole property is omitted. Nested font: { family: null } simply does not emit font-family.
Conditions
✅ null Is Falsey
Official docs: null counts as false for rules and operators that take booleans. That makes values that might be null easy to use in @if and if(). See also Sass Booleans.
styles.scss
@if string.index($label, " ") {
// runs only when a space was found (index is a number, not null)
}
$pad: if($compact, 0.5rem, 1rem);
Cheat Sheet
⚡ Quick Reference
Goal
Code / result
Literal
null
Missing map key
map.get($map, "x") → null
Skip a property
border-radius: null; → property omitted
Skip a list item
18px bold null → 18px bold
Condition
@if $maybe { … } fails when $maybe is null
Optional mixin arg
@mixin btn($shadow: null) { … }
Hands-On
Examples Gallery
Each example shows a practical null behavior. Open View Compiled CSS for verified output.
📚 Getting Started
See where null appears and how CSS drops it.
Example 1 — Common Sources of null
Missing substring, missing map key, and root parent selector.
Default null arguments never become empty CSS values. meta.type-of(null) is the type name null.
Applications
🚀 Real-World Use Cases
Optional mixin properties — radius, shadow, outline only when set.
Token lookups — missing map keys quietly skip a slot in a shorthand.
Parent-aware mixins — branch on whether & exists.
Search helpers — treat string.index / list.index misses as falsey.
Clean CSS — avoid emitting empty or invalid declarations.
🧠 How Compilation Works
1
Produce or pass null
From a helper miss, a default arg, or a literal.
Source
2
Check conditions
Treat null as falsey for @if and if().
Logic
3
Serialize CSS
Drop null list items; omit null-valued properties.
Omit
4
✓
CSS ships clean
Browsers never see the word null—only remaining declarations.
Watch Out
⚠️ Common Pitfalls
Expecting empty string behavior — "" is truthy and still emits in CSS; null does not.
Forgetting property omission — color: null removes the property, it does not write color: null.
Assuming & is always a selector — at the root it is null.
Not handling missing keys — map.get returns null; plan for that.
Confusing with CSS unset / initial — those are CSS keywords; Sass null means “do not emit.”
Pro Tips
💡 Best Practices
✅ Do
Default optional mixin args to null
Use @if $value when a miss should skip a block
Rely on list/property omission for cleaner output
Branch on & when mixins may run at root or nested
Treat helper null returns as intentional “not found”
❌ Don’t
Use "" when you really want a property omitted
Assume every language’s null rules match Sass
Ignore missing map keys in critical design tokens
Emit both a null property and a fallback without an explicit choice
Expect browsers to interpret Sass null at runtime
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Sass null
Absence, omission, and falsey checks at compile time.
5
Core concepts
∅01
Absence
no value
Meaning
🗑️02
Lists
item dropped
CSS
📄03
Properties
fully omitted
CSS
🚫04
Falsey
like false
Logic
✓05
Optional APIs
default null
Pattern
❓ Frequently Asked Questions
null is the only value of its type. It represents the absence of a value and is often returned by functions when there is no result.
That property is omitted entirely from the compiled CSS.
That null is omitted from the generated CSS list, while the other items remain.
Yes. null counts as false for @if, if(), and boolean operators—alongside false itself.
Examples include string.index() when a substring is missing, map.get() when a key is missing, and the parent selector & at the root of a stylesheet.
Default optional parameters to null so unset properties are left out of the CSS instead of writing invalid empty values.
Did you know?
Official Sass docs use the parent selector & as a classic null example—at the root there is no parent, so & is null and can drive if() branches in mixins.
null is Sass’s “no value” signal: falsey in conditions, dropped from lists, and able to omit entire properties. Use it for missing lookups and optional mixin APIs so compiled CSS stays clean.