Sass null

Beginner
⏱️ 12 min read
📚 Updated: Jul 2026
🎯 5 Examples
Absence of a value

What You’ll Learn

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

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.

📝 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
}

🔍 Where null Comes From

ExpressionWhen 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

🗑️ 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.

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);

⚡ Quick Reference

GoalCode / result
Literalnull
Missing map keymap.get($map, "x")null
Skip a propertyborder-radius: null; → property omitted
Skip a list item18px bold null18px bold
Condition@if $maybe { … } fails when $maybe is null
Optional mixin arg@mixin btn($shadow: null) { … }

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.

styles.scss
@use "sass:map";
@use "sass:string";
@use "sass:meta";

$root-parent: &; // null at the stylesheet root

@mixin probe-parent() {
  --inside: #{meta.inspect(&)};
}

.sources {
  --idx: #{meta.inspect(string.index("Helvetica Neue", "Roboto"))};
  --get: #{meta.inspect(map.get(("large": 20px), "small"))};
  --root-parent: #{meta.inspect($root-parent)};
  @include probe-parent;
}

How It Works

At the root, & is null. Inside a rule (or mixin included there), & becomes the current parent selector.

Example 2 — null Dropped From a List

Official-docs style: a missing font family disappears from the shorthand.

styles.scss
@use "sass:map";

$fonts: ("serif": "Helvetica Neue", "monospace": "Consolas");

h3 {
  font: 18px bold map.get($fonts, "sans");
}

How It Works

map.get(..., "sans") is null, so Sass writes 18px bold without a trailing empty family value.

📈 Properties, Parents & Mixins

Skip whole properties, adapt to nesting, and build optional APIs.

Example 3 — Property Omitted When Value Is null

Nested font map: missing family means no font-family rule.

styles.scss
@use "sass:map";

$fonts: ("serif": "Helvetica Neue", "monospace": "Consolas");

h3 {
  font: {
    size: 18px;
    weight: bold;
    family: map.get($fonts, "sans");
  }
}

How It Works

Size and weight emit normally. Because family is null, font-family is not written at all.

Example 4 — Use Falsey & to Adapt Selectors

Official-docs idea: at root write .app-background; when nested, write &.app-background.

styles.scss
@mixin app-background($color) {
  #{if(&, "&.app-background", ".app-background")} {
    background-color: $color;
    color: rgba(#fff, 0.75);
  }
}

@include app-background(#036);

.sidebar {
  @include app-background(#c6538c);
}

How It Works

At the root, & is null (falsey), so if() picks .app-background. Inside .sidebar, & is truthy and the selector becomes .sidebar.app-background.

Example 5 — Optional Mixin Args Default to null

Unset radius/shadow stay out of the CSS; provided values emit normally.

styles.scss
@use "sass:meta";

@mixin button($bg: #036, $radius: null, $shadow: null) {
  background: $bg;
  border: none;
  color: #fff;
  border-radius: $radius;
  box-shadow: $shadow;
}

.btn-plain {
  @include button;
}

.btn-fancy {
  @include button($radius: 8px, $shadow: 0 2px 6px rgba(0, 0, 0, 0.2));
}

.check {
  --a: #{meta.inspect(null == null)};
  --b: #{meta.inspect(if(null, "yes", "no"))};
  --c: #{meta.type-of(null)};
}

How It Works

Default null arguments never become empty CSS values. meta.type-of(null) is the type name null.

🚀 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.

⚠️ Common Pitfalls

  • Expecting empty string behavior"" is truthy and still emits in CSS; null does not.
  • Forgetting property omissioncolor: null removes the property, it does not write color: null.
  • Assuming & is always a selector — at the root it is null.
  • Not handling missing keysmap.get returns null; plan for that.
  • Confusing with CSS unset / initial — those are CSS keywords; Sass null means “do not emit.”

💡 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

Key Takeaways

Knowledge Unlocked

Five things to remember about Sass null

Absence, omission, and falsey checks at compile time.

5
Core concepts
🗑️ 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.

Conclusion

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.

Continue with Sass Variables or @if.

Next: Sass Variables

Learn $names, scope, !default, and !global.

Sass Variables →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful