Sass math.is-unitless()

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

Definition and Usage

math.is-unitless($number) returns whether $number has no units. It is a boolean check only — it does not strip units. Load it with @use "sass:math" (Dart Sass 1.23+ for modules).

Official samples.

math.is-unitless(100) → true · math.is-unitless(100px) → false.

Global name is unitless().

Official docs: the global helper is unitless; the module name is is-unitless so it reads like a yes/no question. Prefer math.is-unitless; global built-ins are deprecated in modern Dart Sass.

Does not remove units.

To cancel a known unit, divide by 1 of that unit — for example math.div(18px, 1px) → 18.

Syntax

SCSS
@use "sass:math";

math.is-unitless($number); //=> boolean

math.is-unitless(100);   // true
math.is-unitless(100px); // false

// Global name (legacy / deprecated in modern Dart Sass)
unitless(100); // true

// Module API — prefer math.is-unitless after @use "sass:math"

Pattern: inspect a token → branch with @if → only then call helpers that require unitless input (math.log, math.pow, math.sqrt). Inspect the unit string with math.unit.

What Counts as Unitless

Verified results for common numbers:

CallResult
math.is-unitless(100)true
math.is-unitless(0)true
math.is-unitless(100px)false
math.is-unitless(50%)false
math.is-unitless(1.5rem)false
math.is-unitless(45deg)false
Any unit fails the check.

Lengths, percentages, angles, and times all return false. Only a bare number returns true.

SCSS Examples

Examples target Dart Sass with @use "sass:math". Open View Compiled CSS for verified output (matches official Sass docs samples).

Example 1 — Official Docs Sample (Unitless)

A bare number has no units.

SCSS
@use "sass:math";

@debug math.is-unitless(100); // true

.basic {
  --a: #{math.is-unitless(100)};
}

How It Works

  1. 100 is a bare number.
  2. No unit string is attached.
  3. Result is true.
  4. Matches the official Sass docs sample.

Example 2 — Official Docs Sample (With Units)

Any CSS unit makes the check fail.

SCSS
@use "sass:math";

@debug math.is-unitless(100px); // false

.units {
  --b: #{math.is-unitless(100px)};
}

How It Works

  1. 100px carries a length unit.
  2. Check returns false.
  3. Does not convert or strip the unit.
  4. Matches the official Sass docs sample.

Example 3 — Other Unit Kinds

Percentages and relative lengths also count as units.

SCSS
@use "sass:math";

.kinds {
  --pct: #{math.is-unitless(50%)};
  --rem: #{math.is-unitless(1.5rem)};
  --zero: #{math.is-unitless(0)};
}

How It Works

  1. % and rem are units → false.
  2. Bare 0 is unitless → true.
  3. Any unit family fails the check the same way.
  4. Use math.unit when you need the unit string.

Example 4 — Cancel Units, Then Recheck

Divide by 1 of the same unit to get a bare number.

SCSS
@use "sass:math";

$px: 18px;
$bare: math.div($px, 1px);

.strip {
  --before: #{math.is-unitless($px)};
  --after: #{math.is-unitless($bare)};
  --value: #{$bare};
}

How It Works

  1. 18px is not unitless.
  2. math.div(..., 1px) cancels px.
  3. Recheck returns true.
  4. Ready for helpers that require unitless input.

Example 5 — Guard a Unitless CSS Property

Only emit a ratio when the token is truly unitless.

SCSS
@use "sass:math";

$n: 1.25;

.gate {
  @if math.is-unitless($n) {
    opacity: $n;
  } @else {
    opacity: 1;
  }
}

How It Works

  1. $n is unitless 1.25.
  2. @if takes the true branch.
  3. Opacity receives the ratio directly.
  4. Useful in mixins that accept either ratios or lengths.

Edge Cases & Pitfalls

Most is-unitless bugs are expecting it to strip units, or calling the deprecated global name.

name

Module vs global naming

Module: math.is-unitless. Global: unitless (deprecated in modern Dart Sass).

strip

Boolean only

Use math.div to cancel units; this helper only answers yes/no.

pct

% is a unit

math.is-unitless(50%) is false, even though percentages look like ratios in CSS.

debug

Inspect with math.unit

When a check surprises you, print the unit string with math.unit.

Sass Support

Prefer the module form with Dart Sass 1.23+.

APIStatus
math.is-unitless()Dart Sass 1.23+ via @use "sass:math"
Global unitless()Works; deprecated in modern Dart Sass
Return typeBoolean
LibSass / Ruby SassUse global unitless() if modules are unavailable

Compile with the Dart Sass CLI.

Key Takeaways

  • Returns a boolean — true when there are no units.
  • Does not strip units — cancel with math.div when needed.
  • Module name is is-unitless; global alias is unitless.
  • Prefer math.is-unitless over deprecated global unitless().

One line: before calling a unitless-only math helper, check with math.is-unitless($number).

Compile Notes

Practical checklist:

checklist.txt
1. @use "sass:math"
2. Call math.is-unitless($number)
3. true → safe for log/pow/sqrt/acos-style helpers
4. false → cancel units with math.div or branch with @if
5. Prefer math.is-unitless over global unitless()

Frequently Asked Questions

math.is-unitless($number) returns true when $number has no CSS units, and false when it has any unit such as px, %, or deg. Example: math.is-unitless(100) is true; math.is-unitless(100px) is false.
Add @use "sass:math"; then call math.is-unitless($number). Prefer this module form in new SCSS.
Official docs expose the global built-in as unitless($number). On sass:math the name is is-unitless to read more like a yes/no question. Prefer math.is-unitless() in new code; global built-ins are deprecated in modern Dart Sass.
No. It only reports whether units are present. To remove a known unit, divide by 1 of that unit—for example math.div(18px, 1px) yields the unitless 18.
Use it before helpers that require unitless input (math.log, math.pow, math.sqrt, math.acos, and friends), or in mixins that accept either ratios or lengths.
Built-in modules with @use need Dart Sass (about 1.23+). Older setups can still call the global unitless() name. Prefer math.is-unitless() for new code.

Next: Sass math.log()

Return the logarithm of a unitless number (natural or with a base).

math.log() →

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