Sass meta.type-of()

Beginner
8 min read
Updated: Nov 2026
5 examples
Dart Sass

Definition and Usage

meta.type-of($value) returns an unquoted string naming the Sass type of $value—for example number, string, list, or map. Load with @use "sass:meta".

Official samples.

meta.type-of(10px) → number · meta.type-of(10px 20px 30px) → list · meta.type-of(()) → list.

Compare unquoted names.

Write @if meta.type-of($v) == number. A quoted "number" is a different string value.

New types may appear.

Official docs: more return values may be added later. Fail safely for unknown types.

Syntax

SCSS
@use "sass:meta";

meta.type-of($value); //=> unquoted string

meta.type-of(10px);           // number
meta.type-of(10px 20px 30px); // list
meta.type-of(());             // list

@if meta.type-of($v) == number {
  // …
}

// Global alias (legacy): type-of($value)
// Prefer meta.type-of after @use "sass:meta"

Pattern: pass any value → get a type name → branch with @if against unquoted names.

Possible Return Values

Official docs currently list these type names:

ReturnExample valueNotes
number10px, 0.5Simplified calc() may become this
string"hello", serifQuoted or unquoted
color#c69, red—
list10px 20px, bare ()Empty () is usually list
map("a": 1)Map-made empty may also be map
calculationcalc(1px + 100%)Unresolved CSS math
bool / nulltrue / null—
function / mixin / module / arglistAdvanced valuesFrom meta helpers / $args...
vs meta.inspect.

meta.inspect shows what a value looks like. type-of answers what kind it is.

SCSS Examples

Examples use @use "sass:meta". Open View Compiled CSS for verified Dart Sass output (matches official Sass docs samples where shown).

Example 1 — Official Number and List Checks

Matches the Sass docs samples for 10px, a space-separated list, and empty ().

SCSS
@use "sass:meta";

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

How It Works

  1. 10px is a number.
  2. Space-separated values form a list.
  3. Bare () is typically list.
  4. Matches the official Sass docs samples.

Example 2 — More Common Types

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

SCSS
@use "sass:meta";

$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

  1. Common scalars map to their type names.
  2. Maps report map.
  3. calc(1px + 100%) stays a calculation.
  4. Simplified calc (e.g. calc(1 + 1)) may become number.

Example 3 — Branch on number

Double numbers; leave other values unchanged.

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

  1. Compare to unquoted number.
  2. 24px doubles to 48px.
  3. Strings pass through unchanged.
  4. Flexible APIs can accept mixed input types.

Example 4 — Handle Lists and Maps Differently

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

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

  1. Store meta.type-of($v) once.
  2. Lists use list.length.
  3. Maps count keys.
  4. Other types return the type string itself.

Example 5 — Guard Before Math

Require numbers before calling math.div.

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

  1. Both args must be numbers.
  2. math.div runs only on the safe path.
  3. Result is 25px.
  4. Bad types stop the compile with @error.

Edge Cases & Pitfalls

Most type-of bugs are quoted comparisons or assuming empty () is always a list.

compare

Use unquoted type names

== number works; == "number" compares a different string.

empty

Empty () can be list or map

Official docs: depends on whether a map function produced it.

calc

calc may simplify

Unresolved calcs are calculation; fully simplified ones may be number.

future

New type names may ship later

Keep an @else / unknown path so new types fail safely.

Sass Support

Prefer the module form with current Dart Sass.

APIStatus
meta.type-of()Dart Sass via @use "sass:meta"
Return typeUnquoted string (type name)
Compare withUnquoted names: number, list, …
Legacy globaltype-of($value)

Compile with the Dart Sass CLI.

Key Takeaways

  • Returns an unquoted type name for any Sass value.
  • Compare without quotes: == number, not == "number".
  • Great for flexible APIs that branch on input shape.
  • Use inspect for snapshots; use type-of for kinds.

One line: to ask what kind of Sass value you have, use meta.type-of($value).

Compile Notes

Practical checklist:

checklist.txt
1. @use "sass:meta"
2. $t: meta.type-of($value)
3. @if $t == number { … }  // unquoted
4. Guard math / color helpers by type
5. Keep an @else for unknown future types

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.

Next: Sass meta.variable-exists()

Check whether a variable exists 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.

8 people found this page helpful