Sass math.percentage()

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

Definition and Usage

math.percentage($number) converts a unitless number (usually a decimal between 0 and 1) into a CSS percentage. Official docs note it is identical to $number * 100%. Load it with @use "sass:math" (Dart Sass 1.23+ for modules; global percentage() also exists).

Official samples.

math.percentage(0.2) → 20% · math.percentage(math.div(100px, 50px)) → 200%.

Same as * 100%.

Use math.percentage($n) or $n * 100% — pick whichever reads clearer. Pair with math.div to build unitless ratios first.

Unitless input only.

Do not pass px or % directly. Cancel units first, and guard with math.is-unitless. Global percentage() is deprecated in modern Dart Sass.

Syntax

SCSS
@use "sass:math";

math.percentage($number); //=> percentage

math.percentage(0.2); // 20%
math.percentage(math.div(100px, 50px)); // 200%

// Identical form from the official docs
0.2 * 100%; // 20%

// Global name (legacy / deprecated in modern Dart Sass)
percentage(0.2); // 20%

// Module API — prefer math.percentage after @use "sass:math"

Pattern: build a unitless ratio → math.percentage → emit a CSS % for widths, columns, or progress tokens.

Decimals and Ratios

Common conversions:

CallResult
math.percentage(0.2)20%
math.percentage(0.5)50%
math.percentage(1)100%
math.percentage(math.div(100px, 50px))200%
0.2 * 100%20% (identical)
Input with unitsError — must be unitless
Not limited to 0…1.

Values above 1 become percentages over 100% (for example a 2:1 ratio → 200%).

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

Turn a unitless decimal into a percentage.

SCSS
@use "sass:math";

@debug math.percentage(0.2); // 20%

.basic {
  --a: #{math.percentage(0.2)};
}

How It Works

  1. Input is unitless 0.2.
  2. Helper multiplies by 100%.
  3. Result is 20%.
  4. Matches the official Sass docs sample.

Example 2 — Official Docs Sample (Ratio from Lengths)

Cancel matching units first, then convert.

SCSS
@use "sass:math";

@debug math.percentage(math.div(100px, 50px)); // 200%

.div {
  --b: #{math.percentage(math.div(100px, 50px))};
}

How It Works

  1. math.div(100px, 50px) cancels to unitless 2.
  2. math.percentage(2) becomes 200%.
  3. Useful for part/whole layout ratios.
  4. Matches the official Sass docs sample.

Example 3 — Identical to * 100%

Official fun fact: both forms compile the same.

SCSS
@use "sass:math";

.identical {
  --fn: #{math.percentage(0.2)};
  --mult: #{0.2 * 100%};
}

How It Works

  1. Both expressions mean the same conversion.
  2. Output is 20% either way.
  3. Pick the form that reads clearer in your mixin.
  4. Matches the official docs fun fact.

Example 4 — Half and Full

Common decimals map to familiar percentages.

SCSS
@use "sass:math";

.range {
  --half: #{math.percentage(0.5)};
  --one: #{math.percentage(1)};
}

How It Works

  1. 0.5 → 50%.
  2. 1 → 100%.
  3. Keep decimals in design tokens; emit % only at the edge.
  4. Opacity stays unitless — do not percentage-wrap it.

Example 5 — Emit a CSS Width

Store a unitless ratio, then convert for layout.

SCSS
@use "sass:math";

$ratio: math.div(3, 4);

.box {
  width: math.percentage($ratio);
  opacity: 0.75; // unitless ratio stays unitless
}

How It Works

  1. 3 / 4 is unitless 0.75.
  2. math.percentage turns it into 75%.
  3. Opacity keeps the bare ratio.
  4. Clear split between percentage lengths and unitless alphas.

Edge Cases & Pitfalls

Most percentage bugs are feeding units, or wrapping opacity-style ratios.

units

Input must be unitless

Cancel with math.div before converting. Check with math.is-unitless.

opacity

Do not percentage-wrap alphas

opacity wants a unitless 0…1 value, not 75%.

global

Global percentage() is deprecated

Prefer math.percentage after @use "sass:math".

range

Over 100% is allowed

Ratios above 1 become percentages above 100% — intentional for some layouts.

Sass Support

Prefer the module form with Dart Sass 1.23+.

APIStatus
math.percentage()Dart Sass 1.23+ via @use "sass:math"
Global percentage()Works; deprecated in modern Dart Sass
InputUnitless number
Equivalent$number * 100%

Compile with the Dart Sass CLI.

Key Takeaways

  • Unitless decimal → CSS % at compile time.
  • Identical to * 100% per official docs.
  • Pair with math.div to cancel length units into a ratio.
  • Prefer math.percentage over deprecated global percentage().

One line: when a unitless Sass ratio must become a CSS percentage, call math.percentage($number).

Compile Notes

Practical checklist:

checklist.txt
1. @use "sass:math"
2. Start from a unitless number (or math.div to cancel units)
3. Call math.percentage($number) — or use $number * 100%
4. Prefer math.percentage over global percentage()
5. Keep opacity/ratios unitless; do not wrap them

Frequently Asked Questions

math.percentage($number) converts a unitless number into a percentage. Example: math.percentage(0.2) is 20%. math.percentage(math.div(100px, 50px)) is 200%.
Add @use "sass:math"; then call math.percentage($number). Prefer this module form in new SCSS.
Yes. Official Sass docs say math.percentage($number) is identical to $number * 100%. Use whichever reads clearer in your stylesheet.
No. The input must be unitless. First cancel units with math.div—for example math.percentage(math.div($part, $whole)). Guard with math.is-unitless().
The global built-in is percentage($number). On sass:math the same helper is math.percentage(). Prefer math.percentage() in new code; global built-ins are deprecated in modern Dart Sass.
Built-in modules with @use need Dart Sass (about 1.23+). Older setups can still call the global percentage() name. Prefer math.percentage() for new code.

Next: Sass math.pow()

Raise a unitless base to a unitless exponent.

math.pow() →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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