Skip to content

Sass: Introspection Functions

How to use Sass introspection functions like variable-exists(), type-of(), and unit() to debug stylesheets by checking variable, mixin existence, data types, and unit compatibility.

The functions in this group allow you to examine the state of Sass itself. You won't use them often when you're building stylesheets, but they're invaluable for figuring out what's going on when something doesn't work quite the way you expected it to.

Sass Introspection Functions

The following table lists all introspection functions in Sass:

Function Description Example Result
variable-exists($name) Returns a Boolean value indicating whether the specified variable exists, either globally or in the current scope $a: 10px; true
variable-exists($not-declared) false
global-variable-exists($name) Returns a Boolean value indicating whether the specified variable exists at the global level $a: 10px; global-variable-exists(a); true
mixin-exists($name) Returns a Boolean value indicating whether the specified mixin exists @mixin text-color {color: red; } true
inspect($value) Returns $value as it is represented by Sass. inspect(12) "12"
type-of($value) Returns a string containing the Sass data type of $value type-of(1 2 3) "list"
unit($number) Returns the unit associated with a number, or an empty string if the number is unitless $a: 10px; "px"
$a: 10; ""
unitless($number) Returns a Boolean value indicating whether the specified number has a unit associated with it $a: 10px; false
comparable($number1, $number2) Returns a Boolean value indicating whether the specified numbers can be added, subtracted or compared comparable(1em, 4em) true
comparable(1em, 3px) false
comparable(1em, 5) true
Navigation