Sass math.is-unitless() Function

Beginner
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
sass:math · Unit Functions

What You’ll Learn

math.is-unitless() is a unit helper in the sass:math module. It answers one question: does this number have any CSS units? This page covers the boolean return, the global unitless() alias, how it guards exponential and inverse-trig helpers, and five compiled examples.

01

Concept

Has units?

02

Module

@use "sass:math"

03

Returns

true / false

04

Global

unitless()

05

Guards

log · pow · sqrt

06

Practice

5 examples

What Is math.is-unitless()?

A Sass number is either unitless (just a magnitude like 100) or it carries a CSS unit (100px, 50%, 45deg). Some math helpers only accept unitless input. Others behave differently when units are present.

math.is-unitless($number) returns whether the value has no units. Official docs place it under Unit Functions next to math.compatible().

  • math.is-unitless(100)true
  • math.is-unitless(100px)false
  • math.is-unitless(math.div(24px, 16px))true (units cancel)
💡
Beginner tip

“Unitless” means no unit string at all—not “zero.” 0 is unitless and returns true; 0px still has a unit and returns false.

📝 Syntax

Load the math module, then call the function:

styles.scss
@use "sass:math";

math.is-unitless($number)

Parameters

ParameterTypeRequiredDescription
$numberNumberYesThe Sass number to inspect (with or without units).

Return value

TypeMeaning
trueThe number has no units (for example 100 or 0.75).
falseThe number has one or more units (for example 100px, 10%, px*px).

📦 Loading sass:math

Prefer the module API. Official docs also document a global name, unitless(), for older stylesheets.

styles.scss
// Recommended — namespaced
@use "sass:math";
$ok: math.is-unitless(100);

// Optional — bring members into the current namespace
@use "sass:math" as *;
$ok: is-unitless(100);

// Optional — custom namespace
@use "sass:math" as m;
$ok: m.is-unitless(100);

// Legacy global name (still works in many setups)
$ok: unitless(100);
⚠️
Name tip

Module form: is-unitless. Global form: unitless. Same check—new SCSS should use math.is-unitless().

📏 What Counts as Unitless?

Any attached unit makes the answer false—including percentages, angles, times, and compound units like px*px. Dividing matching units away (for example px / px) produces a unitless ratio.

CallResultNotes
math.is-unitless(100)trueOfficial example
math.is-unitless(100px)falseOfficial example
math.is-unitless(0)trueZero can still be unitless
math.is-unitless(0px)falseZero with a unit
math.is-unitless(10%)falsePercent is a unit
math.is-unitless(1deg)falseAngles have units
math.is-unitless(math.div(5px, 1px))trueMatching units cancel
math.is-unitless(5px * 10px)falseCompound px*px

🛠 Compatibility

This is about Sass compilers, not browsers. The boolean is resolved while compiling—browsers never see a math.is-unitless() call.

Implementationmath.is-unitless()Notes
Dart Sass (modules)YesUse @use "sass:math" (about 1.23+)
Global unitless()Yes (legacy name)Same idea; prefer the module form in new code
LibSass / Ruby SassNo module APIMay still expose global unitless(); prefer Dart Sass

⚡ Quick Reference

GoalCode
Import math@use "sass:math";
Check for no unitsmath.is-unitless($n)
Plain numbermath.is-unitless(100)true
With unitsmath.is-unitless(100px)false
Strip a known unitmath.div($n, 1px) when $n is in px
Guard before log/pow@if math.is-unitless($n) { ... }
Legacy globalunitless($n)
Debug while learning@debug math.is-unitless(100);

📋 is-unitless vs unitless

Same check, different names depending on how you load Sass math.

math.is-unitless()unitless()
Wheresass:math moduleGlobal built-in
Load with@use "sass:math"No import required
Modern style?Yes—preferredLegacy-friendly
BehaviorBoolean unit presence checkSame idea

📋 Why Other Math Functions Care

FunctionNeeds unitless?How is-unitless helps
math.log() / math.pow() / math.sqrt()YesGuard or strip units first
math.acos() / math.asin() / math.atan()YesConfirm the ratio has no units
math.percentage()Yes (unitless input)Check before converting to %
math.compatible()Different jobCompares two numbers’ units; does not ask “unitless?”

Use math.is-unitless() when you care about one number. Use math.compatible() when you care whether two numbers can work together.

Examples Gallery

Each example uses @use "sass:math". Open View Compiled CSS to see what Dart Sass emits.

📚 Getting Started

Official-style checks from the Sass docs.

Example 1 — Basic math.is-unitless()

Plain numbers are unitless; lengths are not.

styles.scss
@use "sass:math";

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

.demo {
  --plain: #{math.is-unitless(100)};
  --length: #{math.is-unitless(100px)};
}

How It Works

100 has no unit string, so the check is true. 100px carries px, so the check is false.

Example 2 — Units That Cancel

Dividing matching units produces a unitless ratio.

styles.scss
@use "sass:math";

$ratio: math.div(24px, 16px); // 1.5

.scale {
  --is-unitless: #{math.is-unitless($ratio)};

  @if math.is-unitless($ratio) {
    opacity: $ratio;
  }
}

How It Works

px cancels out of the division, leaving 1.5. That value is safe for unitless properties like opacity.

📈 Practical Patterns

Guard exponential math, strip units, and know the legacy alias.

Example 3 — Guard Before math.log()

Logarithms require unitless input—normalize lengths first.

styles.scss
@use "sass:math";

$n: 18px;

.panel {
  @if math.is-unitless($n) {
    --curve: #{math.log($n)};
  } @else {
    // Strip px so log can run
    --curve: #{math.log(math.div($n, 1px))};
  }
}

How It Works

18px fails the unitless check, so the @else branch divides by 1px and then calls math.log(18).

Example 4 — Safe Ratio Mixin

Accept a length or a ready-made ratio and emit opacity safely.

styles.scss
@use "sass:math";

@mixin fade($value, $base: 100px) {
  @if math.is-unitless($value) {
    opacity: $value;
  } @else if math.compatible($value, $base) {
    opacity: math.div($value, $base);
  } @else {
    opacity: 1;
  }
}

.a { @include fade(0.4); }
.b { @include fade(40px); }
.c { @include fade(2em); } // incompatible with 100px → fallback

How It Works

Unitless values pass through. Compatible lengths become a ratio against $base. Incompatible units take the safe fallback.

Example 5 — Module vs Global unitless()

Both names answer the same presence question.

styles.scss
@use "sass:math";

.names {
  --module: #{math.is-unitless(100)};
  --global: #{unitless(100)};
  --with-unit: #{math.is-unitless(12rem)};
}

How It Works

Module and global forms agree on 100. 12rem still has a unit, so it is false.

🚀 Real-World Use Cases

  • Before log / pow / sqrt — those helpers reject lengths; check or strip first.
  • Opacity and scales — confirm a token is a ratio, not a length.
  • Flexible mixins — accept either 0.5 or 50px / 100px style inputs.
  • Design-token validation — assert that multiplier maps stay unitless.
  • Inverse trig inputs — guard acos/asin/atan ratios.
  • Learning units — print true/false while exploring how division cancels units.

🧠 How Compilation Works

1

Write SCSS

Call math.is-unitless($n) after @use.

Source
2

Inspect units

Sass looks at whether the number carries any unit string.

Validate
3

Return a boolean

true means bare magnitude; false means units are present.

Result
4

Branches compile away

Your @if path ships only the CSS that matched.

⚠️ Common Pitfalls

  • Thinking zero is special0px is still not unitless.
  • Expecting stripping — the function only reports; use math.div to remove a known unit.
  • Percentages% counts as a unit, so is-unitless(50%) is false.
  • Confusing the two names — module = is-unitless, global = unitless.
  • Skipping the check before log/pow — those calls error on lengths at compile time.

💡 Best Practices

✅ Do

  • Use @use "sass:math" and math.is-unitless() in new SCSS
  • Guard log, pow, sqrt, and inverse-trig helpers
  • Cancel units with math.div when you need a ratio
  • Pair with math.compatible() when comparing two lengths
  • Prefer Dart Sass for the modern module API

❌ Don’t

  • Assume true means the value is between 0 and 1
  • Treat % as unitless
  • Rely on LibSass for sass:math
  • Ship debug custom properties in production unless you need them
  • Forget the global name is unitless, not is-unitless

Key Takeaways

Knowledge Unlocked

Five things to remember about math.is-unitless()

Boolean unit presence—true means no CSS units.

5
Core concepts
📦 02

Module

sass:math

@use
📏 03

Returns

boolean

true/false
04

Global

unitless()

Alias
05

Use

guard math

@if

❓ 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.
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. LibSass and Ruby Sass do not load sass:math the same way.
Did you know?

Official Sass docs list math.is-unitless under Unit Functions with math.compatible and math.unit. The global twin is simply named unitless()—shorter, but less explicit than is-unitless.

Conclusion

math.is-unitless() is a simple boolean check for missing CSS units. Use it before helpers that reject lengths, remember the global alias is unitless(), and keep new code on @use "sass:math".

Continue with math.log(), math.compatible(), or math.sqrt().

More Sass Math

Continue with logarithms in the math module.

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.

5 people found this page helpful