math.sqrt() is an exponential helper in the sass:math module. It returns the square root of a unitless number. You will learn unit rules, NaN behavior, comparisons with math.pow and math.hypot, Dart Sass 1.25+ notes, and five compiled examples.
01
Concept
Square root
02
Module
@use "sass:math"
03
Call
math.sqrt($n)
04
Units
Unitless only
05
Since
Dart Sass 1.25+
06
Practice
5 examples
Concept
What Is math.sqrt()?
A square root answers: what number, multiplied by itself, gives this value? In Sass:
math.sqrt(100) → 10 (because 10 × 10 = 100)
math.sqrt(math.div(1, 3)) → about 0.5773502692
math.sqrt(-1) → NaN (no real square root)
Official docs group it with math.pow() and math.log() under Exponential Functions. It is the readable form of math.pow($n, 0.5).
💡
Beginner tip
Browsers never see math.sqrt. Dart Sass evaluates it and writes a plain number into your .css file. Reattach units yourself when needed: $side * math.sqrt(2) for a square’s diagonal factor.
Foundation
📝 Syntax
Load the math module, then pass a unitless number:
styles.scss
@use "sass:math";
math.sqrt($number)
// $number must be unitless
Parameters
Parameter
Type
Required
Description
$number
Number
Yes
Value to take the square root of. Must be unitless.
Return value
Type
Situation
Result
Number
Non-negative unitless input
√$number (unitless)
Number
Negative input
NaN (as in the official docs)
Error
Argument has units
Compile fails—strip units first or multiply a length after
Modules
📦 Loading sass:math
styles.scss
// Recommended — namespaced
@use "sass:math";
$r: math.sqrt(100);
// Optional — bring members into the current namespace
@use "sass:math" as *;
$r: sqrt(100);
// Optional — custom namespace
@use "sass:math" as m;
$r: m.sqrt(100);
⚠️
Put @use first
Keep @use "sass:math"; near the top of the file. math.sqrt() needs Dart Sass 1.25+.
Numbers
📏 How Units Work
Like math.pow() and math.log(), math.sqrt() accepts only unitless numbers. Use ratios for length math, or multiply the root by a length.
Call
Result (approx.)
Notes
math.sqrt(100)
10
Official example
math.sqrt(math.div(1, 3))
~0.5773502692
Official fractional example
math.sqrt(-1)
NaN
No real square root
16px * math.sqrt(2)
~22.627416998px
Reattach units after sqrt
math.sqrt(math.div(9px, 1px))
3
Strip units with a same-unit ratio first
math.sqrt(100px)
—
Error: must be unitless
Support
🛠 Compatibility
This is about Sass compilers, not browsers. Compiled CSS receives a plain number (or NaN if the input was negative).
Implementation
math.sqrt()
Notes
Dart Sass 1.25+
Yes
Preferred; needs @use "sass:math"
Dart Sass < 1.25
No
Upgrade Dart Sass
LibSass / Ruby Sass
No module API
Use Dart Sass for exponential math helpers
Cheat Sheet
⚡ Quick Reference
Goal
Code
Import math
@use "sass:math";
Perfect square
math.sqrt(100) → 10
Fraction
math.sqrt(math.div(1, 3))
Negative input
math.sqrt(-1) → NaN
Same as half power
math.pow($n, 0.5) ≈ math.sqrt($n)
Diagonal factor
$side * math.sqrt(2)
Debug while learning
@debug math.sqrt(100);
Compare
📋 sqrt vs pow vs hypot
Function
What it does
Best for
math.sqrt($n)
Square root of one unitless number
Clear √n when you already have a single value
math.pow($n, 0.5)
Same math, more general API
When you already use pow for other exponents
math.hypot($a, $b)
√(a² + b² …) with unit support
Diagonals / vector length from components
Prefer math.sqrt for a single square root. Prefer math.hypot() when you have two or more sides and want Sass to handle compatible length units.
Compare
📋 Sass math.sqrt() vs CSS / JS sqrt
Sass math.sqrt()
JS Math.sqrt / CSS sqrt()
When it runs
Compile time (Dart Sass)
In the browser / runtime
Appears in CSS output?
No — only the numeric result
CSS sqrt() can stay in the stylesheet (modern browsers)
Units
Unitless only
JS: plain numbers; CSS: follows CSS math rules
Best for
Fixed design tokens in SCSS
Dynamic or fluid values that must resolve at runtime
Hands-On
Examples Gallery
Each example uses @use "sass:math". Open View Compiled CSS to see what Dart Sass emits.
📚 Getting Started
Official-style square roots, fractions, and NaN.
Example 1 — Basic math.sqrt()
Take the square root of a perfect square—same as the official docs.
Negative roots — you get NaN, not an error; guard with math.abs when needed.
Reinventing hypot — for multi-component lengths with units, prefer math.hypot.
Old Dart Sass — need 1.25+; LibSass lacks the module API.
Pro Tips
💡 Best Practices
✅ Do
Use @use "sass:math" and math.sqrt() in new SCSS
Keep the argument unitless
Multiply by rem/px after computing the root factor
Prefer math.hypot for multi-side length math
Prefer Dart Sass 1.25+
❌ Don’t
Expect the browser to re-evaluate math.sqrt
Pass lengths with units directly into math.sqrt
Ignore NaN from negative inputs in production tokens
Use Sass sqrt for live measured layout (use JS / CSS instead)
Rely on LibSass for sass:math
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about math.sqrt()
Compile-time square root—unitless only; negatives become NaN.
5
Core concepts
📝01
Call
math.sqrt($n)
API
📦02
Module
sass:math
@use
√03
Same as
pow($n, 0.5)
Alias idea
📏04
Units
unitless only
Rule
⚡05
Since
Dart Sass 1.25+
Tooling
❓ Frequently Asked Questions
math.sqrt($number) returns the square root of a unitless number. Example: math.sqrt(100) is 10; math.sqrt(math.div(1, 3)) is about 0.5773502692.
Add @use "sass:math"; then call math.sqrt($number). Requires Dart Sass 1.25+.
No. Official docs require $number to be unitless. Strip units with a ratio first, or multiply the result by a length afterward—for example 16px * math.sqrt(2).
math.sqrt(-1) returns NaN (not a number), matching the official Sass docs. Avoid negatives unless you intentionally handle NaN.
math.sqrt($n) is the clear square-root form of math.pow($n, 0.5). math.hypot(a, b) is √(a² + b²) and can keep compatible length units; sqrt alone needs unitless input.
Official docs expose this as math.sqrt() on sass:math. Prefer the module form with @use "sass:math".
Did you know?
Official Sass docs place math.sqrt under Exponential Functions with math.pow and math.log. The example math.sqrt(-1) returning NaN is intentional—Sass stays in real numbers, not complex ones.
math.sqrt() gives you compile-time square roots for unitless numbers. Reattach lengths afterward, watch for NaN on negatives, and reach for math.hypot when you are combining multiple length components.