meta.type-of() belongs to the built-in sass:meta module. It returns an unquoted string naming the type of any Sass value. This page covers common return values, safe @if branching, the empty () gotcha, and five compiled examples.
01
Concept
Ask “what type is this?”
02
Module
@use "sass:meta"
03
Returns
Unquoted string
04
Compare
== number (unquoted)
05
Gotcha
Empty () list vs map
06
Practice
5 examples
Concept
What Is meta.type-of()?
Official docs: returns the type of $value as an unquoted string. Use it when a mixin or function accepts mixed inputs and needs different behavior for numbers, lists, maps, colors, and more.
Works on any Sass value at compile time.
Compare results to unquoted names like number or list.
New type names may be added in future Sass versions.
Empty () may be a list or a map depending on origin.
💡
Beginner tip
Think of a luggage tag: type-of tells you the bag is a “number” or a “list”. It does not open the bag or convert the value.
Foundation
📝 Syntax
styles.scss
@use "sass:meta";
// Recommended
meta.type-of($value)
// Legacy global name
type-of($value)
Parameters
Parameter
Type
Required
Description
$value
Any
Yes
The Sass value whose type you want to know.
Return value
Type
Result
Unquoted string
A type name such as number, list, or map
Reference
📋 Possible Return Values
Official docs list these common results (new names may appear later):
Returns
Example value
number
10px, 0.5, simplified calc(1 + 1)
string
"hello", sans-serif
color
#c69, teal
list
10px 20px, bare ()
map
("a": 1)
calculation
Unresolved calc(1px + 100%)
bool
true, false
null
null
function
A value from meta.get-function
arglist
A rest parameter $args...
mixin
A value from meta.get-mixin (Dart Sass 1.69+)
Modules
📦 Loading sass:meta
styles.scss
// Recommended — namespaced
@use "sass:meta";
$t: meta.type-of(10px); // number
// Optional — bring members into scope
@use "sass:meta" as *;
$t: type-of(10px);
// Legacy global
$t: type-of(10px);
Details
⚖️ Comparing Types Safely
Because the result is an unquoted string, compare it to unquoted identifiers:
styles.scss
@use "sass:meta";
@if meta.type-of($value) == number {
// OK — both sides unquoted
}
// Avoid this unless you intentionally want a quoted string:
// @if meta.type-of($value) == "number" { ... }
Official note: empty () may return list or map depending on whether a map function produced it.
Support
🛠 Compatibility
This is about Sass compilers, not browsers. The check runs at compile time.
Implementation
type-of
Dart Sass
Yes — prefer meta.type-of
LibSass
Yes (legacy global / limited newer types)
Ruby Sass
Yes (legacy global / limited newer types)
Prefer current Dart Sass for types like calculation and mixin.
Cheat Sheet
⚡ Quick Reference
Goal
Code
Import meta
@use "sass:meta";
Get a type name
meta.type-of(10px) → number
Branch on type
@if meta.type-of($v) == list { … }
Guard math helpers
@if meta.type-of($n) == number { … }
Detect calc leftovers
meta.type-of(calc(1px + 100%)) → calculation
Legacy global
type-of($value)
Hands-On
Examples Gallery
Each example uses meta.type-of at compile time. Open View Compiled CSS for verified Dart Sass output.
📚 Getting Started
Official number / list checks, then a wider type tour.
Example 1 — Official Number and List Checks
Matches the Sass docs samples for 10px, a space-separated list, and empty ().
Browsers never see meta.type-of—only finished values.
Watch Out
⚠️ Common Pitfalls
Quoted comparisons — prefer == number, not == "number".
Empty () — may be list or map; do not assume one forever.
Calc simplification — some calc() expressions become number.
Expecting JS types — Sass has its own type names (for example bool, not boolean).
Runtime checks — everything resolves when Sass compiles.
Pro Tips
💡 Best Practices
✅ Do
Use @use "sass:meta" and meta.type-of()
Compare to unquoted type names
Store the result once when branching several ways
Fail safely for unknown future types
Pair with meta.inspect while debugging
❌ Don’t
Assume empty () is always a list
Treat Sass types as identical to JavaScript types
Expect the browser to evaluate the check
Forget that simplified calcs may be numbers
Skip guards before math on mixed APIs
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about meta.type-of()
Ask for a Sass value’s type name, then branch with unquoted comparisons.
5
Core concepts
📝01
API
type-of($value)
Call
📦02
Module
sass:meta
@use
📄03
Returns
unquoted string
Result
⚖️04
Compare
== number / list
Pattern
✓05
Gotcha
() list or map
Watch
❓ Frequently Asked Questions
meta.type-of($value) returns an unquoted string that names the Sass type of $value—for example number, string, color, list, or map.
Compare against unquoted type names: @if meta.type-of($v) == number { … }. Quoted "number" is a different string value.
Official docs: empty () may be list or map depending on whether a map function produced it. A bare () is typically list.
Unresolved calculations return calculation. Some calcs simplify to a number at compile time—those return number instead.
Yes. type-of($value) is the legacy global name. Prefer meta.type-of after @use "sass:meta".
Yes. Official docs say new possible values may be added in the future—write @if branches that fail safely for unknown types.
Did you know?
Official Sass docs warn that empty () can be either a list or a map. That single quirk is why many helpers check meta.type-of before calling list.length or map.keys.
meta.type-of() returns an unquoted string naming a Sass value’s type. Compare with identifiers like number and list, watch the empty () case, and use it to build safer mixins and functions.