Sass math.percentage() Function

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

What You’ll Learn

math.percentage() turns a unitless decimal into a CSS % value in the sass:math module. This page covers the unitless rule, the fun fact that it equals $number * 100%, pairing with math.div(), the global percentage() alias, and five compiled examples.

01

Concept

Decimal → %

02

Module

@use "sass:math"

03

Input

Unitless only

04

Same as

* 100%

05

Global

percentage()

06

Practice

5 examples

What Is math.percentage()?

Design tokens often store fractions like 0.2 or ratios from math.div. CSS widths, columns, and progress bars usually want 20% instead. math.percentage($number) multiplies that unitless value by 100% for you.

Official docs place it under Other Functions and call out a fun fact: it is identical to writing $number * 100%.

  • math.percentage(0.2)20%
  • math.percentage(math.div(100px, 50px))200%
  • math.percentage(1)100%
💡
Beginner tip

Think “fraction of a whole.” 0.25 means a quarter; math.percentage(0.25) writes that quarter as 25% in CSS.

📝 Syntax

Load the math module, then call the function:

styles.scss
@use "sass:math";

math.percentage($number)

Parameters

ParameterTypeRequiredDescription
$numberNumber (unitless)YesUsually a decimal between 0 and 1, but any unitless number works (for example 2200%).

Return value

TypeMeaning
Number with %The input multiplied by 100% (same as $number * 100%).

📦 Loading sass:math

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

styles.scss
// Recommended — namespaced
@use "sass:math";
$w: math.percentage(0.2);

// Optional — bring members into the current namespace
@use "sass:math" as *;
$w: percentage(0.2);

// Optional — custom namespace
@use "sass:math" as m;
$w: m.percentage(0.2);

// Legacy global name (still works in many setups)
$w: percentage(0.2);
⚠️
Put @use first

Keep @use "sass:math"; near the top of the file so math.percentage is available everywhere below.

📏 Unitless Input Only

The argument must have no units. Lengths like 20px fail. Cancel units first with math.div(), then convert.

CallResultNotes
math.percentage(0.2)20%Official example
math.percentage(math.div(100px, 50px))200%Official example—units cancel first
math.percentage(0)0%Valid edge
math.percentage(1)100%Full width / full scale
0.2 * 100%20%Identical to math.percentage(0.2)
math.percentage(20px)Error: input must be unitless

🛠 Compatibility

This is about Sass compilers, not browsers. Compiled CSS receives a finished percentage—no math.percentage() call remains.

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

⚡ Quick Reference

GoalCode
Import math@use "sass:math";
Decimal to percentmath.percentage(0.2)20%
Ratio to percentmath.percentage(math.div($a, $b))
Same math, multiply form0.2 * 100%20%
Full scalemath.percentage(1)100%
Legacy globalpercentage(0.2)
Debug while learning@debug math.percentage(0.2);

📋 percentage() vs * 100%

Official docs treat them as the same operation—pick the clearer style.

math.percentage($n)$n * 100%
ResultSame percentageSame percentage
ReadabilityIntent is obvious (“make a %”)Shows the arithmetic directly
ModuleNeeds sass:math (or global)No import required
When to preferNamed helpers / shared tokensOne-off inline math

📋 Pairing with math.div()

StepCodeWhy
1. Cancel unitsmath.div(100px, 50px)2Produces a unitless ratio
2. Convert to %math.percentage(...)200%Turns the ratio into a CSS percentage
One linemath.percentage(math.div($part, $whole))Common column / progress pattern

Examples Gallery

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

📚 Getting Started

Official-style conversions from the Sass docs.

Example 1 — Basic math.percentage()

Turn a decimal fraction into a CSS percentage.

styles.scss
@use "sass:math";

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

.panel {
  width: math.percentage(0.2);
}

How It Works

0.2 means 20% of a whole. Sass multiplies by 100% and writes 20% into the stylesheet.

Example 2 — Ratio from math.div()

Cancel length units, then convert the unitless ratio.

styles.scss
@use "sass:math";

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

.hero {
  flex-basis: math.percentage(math.div(100px, 50px));
}

How It Works

math.div(100px, 50px) becomes unitless 2. math.percentage(2) then becomes 200%.

📈 Practical Patterns

Prove the * 100% twin, build grids, and know the global alias.

Example 3 — Identical to * 100%

Both forms compile to the same percentage.

styles.scss
@use "sass:math";

$fraction: 0.35;

.box {
  width: math.percentage($fraction);
  max-width: $fraction * 100%;
}

How It Works

Official docs’ fun fact in action: the helper and the multiply form are the same math, so both properties become 35%.

Example 4 — Column Width Tokens

Store column shares as decimals, emit CSS percentages.

styles.scss
@use "sass:math";

$cols: 12;
$span-main: 8;
$span-side: 4;

.main {
  width: math.percentage(math.div($span-main, $cols));
}

.side {
  width: math.percentage(math.div($span-side, $cols));
}

How It Works

8 / 12 and 4 / 12 become unitless ratios, then percentages suitable for a classic 12-column layout.

Example 5 — Module vs Global percentage()

Both names produce the same percentage value.

styles.scss
@use "sass:math";

.names {
  width: math.percentage(0.5);
  min-width: percentage(0.25);
}

How It Works

Module and global forms agree. Prefer math.percentage() so readers see the helper comes from sass:math.

🚀 Real-World Use Cases

  • Grid / column spans — convert span / columns into % widths.
  • Progress and meters — turn 0–1 completion tokens into bar widths.
  • Design tokens — keep fractions in maps, emit percentages at the edge.
  • Fluid layouts — derive width, flex-basis, or max-width from ratios.
  • After math.div — cancel units, then label the ratio as a percent.
  • Readable helpers — prefer math.percentage when intent matters more than showing * 100%.

🧠 How Compilation Works

1

Write SCSS

Call math.percentage($n) after @use.

Source
2

Require unitless

Sass rejects inputs that still carry px, em, and friends.

Validate
3

Multiply by 100%

Same math as $n * 100%—a percentage number.

Convert
4

Plain CSS ships

The browser receives a finished % value.

⚠️ Common Pitfalls

  • Passing lengthsmath.percentage(20px) fails; cancel units first.
  • Double-scaling — if the token is already 20 meaning “20 percent,” do not also call percentage (that becomes 2000%).
  • Confusing % with unitless0.2 is unitless; 20% already has a unit.
  • Expecting clamping — values outside 0–1 still convert (2200%).
  • Forgetting math.div — length ratios need division before percentage.

💡 Best Practices

✅ Do

  • Use @use "sass:math" and math.percentage() in new SCSS
  • Keep design tokens as unitless fractions when possible
  • Pair with math.div() for part/whole length ratios
  • Use * 100% when the multiply form is clearer
  • Prefer Dart Sass for the modern module API

❌ Don’t

  • Pass px, em, or % inputs
  • Apply percentage twice to an already-percent-minded number
  • Rely on LibSass for sass:math
  • Expect the browser to re-evaluate math.percentage
  • Mix up opacity decimals (unitless) with CSS % without converting

Key Takeaways

Knowledge Unlocked

Five things to remember about math.percentage()

Unitless decimal in—CSS % out (same as * 100%).

5
Core concepts
📦 02

Module

sass:math

@use
📏 03

Input

unitless

Rule
04

Same as

n * 100%

Docs
05

Pair

math.div

Ratio

❓ 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)).
The global built-in is percentage($number). On sass:math the same helper is math.percentage(). Prefer math.percentage() in new code.
Built-in modules with @use need Dart Sass (about 1.23+). Older setups can still call the global percentage() name. LibSass and Ruby Sass do not load sass:math the same way.
Did you know?

Official Sass docs list math.percentage under Other Functions and highlight the fun fact that it is identical to $number * 100%—so you can choose the named helper or the multiply form without changing the compiled CSS.

Conclusion

math.percentage() converts unitless decimals into CSS percentages—the same math as $number * 100%. Keep inputs unitless, pair with math.div() for part/whole lengths, and prefer @use "sass:math" in new SCSS.

Continue with math.div(), math.pow(), or math.is-unitless().

More Sass Math

Continue with exponentiation in the math module.

math.pow() →

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