Sass meta.type-of() Function

Beginner
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
sass:meta · type checks

What You’ll Learn

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

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.

📝 Syntax

styles.scss
@use "sass:meta";

// Recommended
meta.type-of($value)

// Legacy global name
type-of($value)

Parameters

ParameterTypeRequiredDescription
$valueAnyYesThe Sass value whose type you want to know.

Return value

TypeResult
Unquoted stringA type name such as number, list, or map

📋 Possible Return Values

Official docs list these common results (new names may appear later):

ReturnsExample value
number10px, 0.5, simplified calc(1 + 1)
string"hello", sans-serif
color#c69, teal
list10px 20px, bare ()
map("a": 1)
calculationUnresolved calc(1px + 100%)
booltrue, false
nullnull
functionA value from meta.get-function
arglistA rest parameter $args...
mixinA value from meta.get-mixin (Dart Sass 1.69+)

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

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

🛠 Compatibility

This is about Sass compilers, not browsers. The check runs at compile time.

Implementationtype-of
Dart SassYes — prefer meta.type-of
LibSassYes (legacy global / limited newer types)
Ruby SassYes (legacy global / limited newer types)

Prefer current Dart Sass for types like calculation and mixin.

⚡ Quick Reference

GoalCode
Import meta@use "sass:meta";
Get a type namemeta.type-of(10px)number
Branch on type@if meta.type-of($v) == list { … }
Guard math helpers@if meta.type-of($n) == number { … }
Detect calc leftoversmeta.type-of(calc(1px + 100%))calculation
Legacy globaltype-of($value)

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 ().

styles.scss
@use "sass:meta";

.probe {
  --number: #{meta.type-of(10px)};
  --list: #{meta.type-of(10px 20px 30px)};
  --empty: #{meta.type-of(())};
}

How It Works

Bare () is a list here. A map-produced empty value could instead report map.

Example 2 — More Common Types

Strings, colors, booleans, null, maps, and unresolved calculations.

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

$m: ("a": 1);

.probe {
  --string: #{meta.type-of("hello")};
  --color: #{meta.type-of(#c69)};
  --bool: #{meta.type-of(true)};
  --null: #{meta.type-of(null)};
  --map: #{meta.type-of($m)};
  --calc: #{meta.type-of(calc(1px + 100%))};
}

How It Works

calc(1px + 100%) stays a calculation. A fully simplified calc(1 + 1) would instead return number.

📈 Practical Patterns

Branching helpers and input guards for safer APIs.

Example 3 — Branch on number

Double numbers; leave other values unchanged.

styles.scss
@use "sass:meta";

@function scale-if-number($v) {
  @if meta.type-of($v) == number {
    @return $v * 2;
  }
  @return $v;
}

.box {
  width: scale-if-number(24px);
  content: scale-if-number("ok");
}

How It Works

24px is a number, so it becomes 48px. The string "ok" passes through unchanged.

Example 4 — Handle Lists and Maps Differently

Return a length for collections; otherwise echo the type name.

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

@function describe($v) {
  $t: meta.type-of($v);
  @if $t == list {
    @return list.length($v);
  }
  @if $t == map {
    @return list.length(map.keys($v));
  }
  @return $t;
}

.probe {
  --list-len: #{describe(a b c)};
  --map-len: #{describe(("x": 1, "y": 2))};
  --other: #{describe(true)};
}

How It Works

Store meta.type-of($v) once, then branch. Non-collections fall through and return the type string itself.

Example 5 — Guard Before Math

Require numbers before calling math.div.

styles.scss
@use "sass:meta";
@use "sass:math";

@function safe-div($a, $b) {
  @if meta.type-of($a) != number or meta.type-of($b) != number {
    @error "safe-div expects numbers";
  }
  @return math.div($a, $b);
}

.box {
  width: safe-div(100px, 4);
}

How It Works

Both arguments are numbers, so math.div(100px, 4) becomes 25px. Bad types would stop the compile with @error.

🚀 Real-World Use Cases

  • Flexible APIs — accept a number or a list and branch accordingly.
  • Token validation — ensure theme values are colors before mixing.
  • Safer math — guard math.div / math.pow inputs.
  • Debugging — print types next to meta.inspect while learning.
  • Calc awareness — detect unresolved calculation values.

🧠 How Compilation Works

1

Pass any Sass value

Call meta.type-of($value).

Source
2

Sass classifies it

Returns an unquoted type name like number or map.

Compile
3

Your @if branches

Compare to unquoted names and keep or skip logic.

Branch
4

CSS ships

Browsers never see meta.type-of—only finished values.

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

💡 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

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

Conclusion

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.

Continue with meta.variable-exists() or the Sass introduction.

Next: check if a variable exists

Learn meta.variable-exists() to guard optional variables in the current scope.

meta.variable-exists() →

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