meta.variable-exists($name) returns a boolean: whether a variable named $name exists in the current scope. Pass the name without the $. Load with @use "sass:meta".
Official sample idea.
meta.variable-exists("var1") is false until you declare $var1; a local $var2 inside a rule returns true in that scope.
Locals and globals.
Unlike meta.global-variable-exists, this helper sees variables declared in the current scope—including locals inside rules and mixins.
No $module argument.
It only takes $name. For namespaced module variables, use global-variable-exists with $module, or module-variables.
Syntax
Syntax
SCSS
@use "sass:meta";
meta.variable-exists($name); //=> boolean
meta.variable-exists("var1"); // false until defined
$var1: value;
meta.variable-exists("var1"); // true
h1 {
$var2: value; // local
meta.variable-exists("var2"); // true here
}
// Global alias (legacy): variable-exists($name)
// Prefer meta.variable-exists after @use "sass:meta"
Pattern: pass a bare name → get true/false for the current scope → branch with @if.
Reference
Current Scope vs Global
Same name, different helpers:
Where declared
variable-exists
global-variable-exists
File root / global scope
true
true
Inside a rule / mixin / function
true (in that scope)
false
Never declared
false
false
$module support
No
Yes
Official contrast.
Docs show a local $var2 inside h1: variable-exists is true; global-variable-exists is false.
Returns true/false for a variable in the current scope.
Sees locals and globals; pass bare names without $.
No $module — use global-variable-exists for namespaces.
Prefer @use "sass:meta" over the legacy global name.
One line: to ask whether a variable exists where you are, use meta.variable-exists($name).
Practice
Compile Notes
Practical checklist:
checklist.txt
1. @use "sass:meta"
2. Pass bare name without $
3. Check in the scope where you need the answer
4. Branch with @if for optional values
5. Use global-variable-exists for globals-only / $module
Frequently Asked Questions
meta.variable-exists($name) returns true if a variable named $name exists in the current scope, otherwise false. Pass the name without the $.
No. Official docs use the bare name: meta.variable-exists("var1") checks $var1.
variable-exists finds locals and globals in the current scope. global-variable-exists only finds globals—a variable declared inside a rule is local, so global-variable-exists is false while variable-exists is true.
No. Unlike global-variable-exists, variable-exists only takes $name and checks the current scope.
Yes. variable-exists($name) is the legacy global name. Prefer meta.variable-exists after @use "sass:meta".
No. It runs at compile time. Browsers only see the CSS after your @if branches resolve.