math.tan() is a trigonometric helper in the sass:math module. It returns the tangent of an angle—the slope ratio (rise ÷ run). You will learn angle units, the unitless-as-radians rule, Dart Sass 1.25+ notes, and five compiled examples.
01
Concept
Tangent / slope
02
Module
@use "sass:math"
03
Angles
deg / rad / unitless
04
Result
Unitless ratio
05
Since
Dart Sass 1.25+
06
Practice
5 examples
Concept
What Is math.tan()?
Tangent answers: for this angle, how much rise do I get per unit of run? In Sass it returns that ratio as a unitless number:
math.tan(100deg) → about -5.6712818196
math.tan(1rad) → about 1.5574077247
math.tan(1) → same as 1rad (unitless = radians)
math.tan(45deg) → 1 (equal rise and run)
Official docs place it under Trigonometric Functions with math.sin() and math.cos(). Algebraically, tan = sin / cos for the same angle.
💡
Beginner tip
Browsers never see math.tan. Dart Sass evaluates it and writes a plain number into your .css file. Near 90deg, cosine approaches zero, so tangent grows very large—prefer moderate design angles for UI slopes.
Foundation
📝 Syntax
Load the math module, then pass an angle or a unitless radian value:
styles.scss
@use "sass:math";
math.tan($number)
// angle (deg-compatible) or unitless → radians
Parameters
Parameter
Type
Required
Description
$number
Number
Yes
An angle whose units are compatible with deg (e.g. deg, rad, turn, grad), or a unitless number treated as radians.
Return value
Type
Situation
Result
Number
Valid angle or unitless radian
Unitless tangent (slope ratio)
Error
Incompatible units (e.g. px)
Compile fails—pass an angle, not a length
Modules
📦 Loading sass:math
styles.scss
// Recommended — namespaced
@use "sass:math";
$t: math.tan(45deg);
// Optional — bring members into the current namespace
@use "sass:math" as *;
$t: tan(45deg);
// Optional — custom namespace
@use "sass:math" as m;
$t: m.tan(45deg);
⚠️
Put @use first
Keep @use "sass:math"; near the top of the file. math.tan() needs Dart Sass 1.25+.
Numbers
📏 How Units Work
Pass an angle, or omit units to mean radians. The result is always unitless—multiply by a run length when you need the rise as a CSS length.
Call
Result (approx.)
Notes
math.tan(100deg)
-5.6712818196
Official example
math.tan(1rad)
1.5574077247
Official example
math.tan(1)
1.5574077247
Unitless = radians
math.tan(0deg)
0
Flat slope
math.tan(45deg)
1
Rise equals run
120px * math.tan(30deg)
~69.2820323px
Rise from a known run
math.tan(10px)
—
Error: not an angle
Support
🛠 Compatibility
This is about Sass compilers, not browsers. Compiled CSS receives a plain number.
Implementation
math.tan()
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 trigonometric helpers
Cheat Sheet
⚡ Quick Reference
Goal
Code
Import math
@use "sass:math";
Tangent in degrees
math.tan(100deg)
Tangent in radians
math.tan(1rad) or math.tan(1)
Rise from a run
$run * math.tan($angle)
Same as sin/cos
math.sin($a) / math.cos($a)
Debug while learning
@debug math.tan(45deg);
Compare
📋 tan vs sin vs cos
Function
What it returns
Common use
math.tan($angle)
Slope ratio (sin/cos)
Ramps, skews, rise from a known run
math.sin($angle)
Vertical / opposite factor
Y on a circle
math.cos($angle)
Horizontal / adjacent factor
X on a circle
Prefer math.tan when you already know the horizontal run and need the vertical rise. Prefer sin/cos when you place a point on a circle from a radius.
Compare
📋 Sass math.tan() vs CSS / JS tan
Sass math.tan()
CSS tan() / JS Math.tan
When it runs
Compile time (Dart Sass)
In the browser / runtime
Appears in CSS output?
No — only the numeric result
CSS tan() can stay in the stylesheet
Unitless input
Treated as radians
JS: radians; CSS: follows CSS angle rules
Best for
Fixed slopes known in SCSS
Dynamic angles, animated custom properties
Hands-On
Examples Gallery
Each example uses @use "sass:math". Open View Compiled CSS to see what Dart Sass emits.
At 45°, rise equals run, so tangent is 1. At 30°, the slope is 1/√3 ≈ 0.577.
Example 3 — Unitless Means Radians
A common beginner trap: forgetting that bare numbers are radians.
styles.scss
@use "sass:math";
.compare {
// These match (1 radian)
--as-rad: #{math.tan(1rad)};
--unitless: #{math.tan(1)};
// This is different (1 degree)
--as-deg: #{math.tan(1deg)};
}
Both paths produce the official math.tan(100deg) result. Prefer math.tan when the slope form is clearer than writing the division yourself.
Applications
🚀 Real-World Use Cases
Ramps and wedges — compute height from a fixed width and angle.
Skew / slant tokens — bake a slope ratio into custom properties.
Clip-path helpers — derive vertical cuts from a known horizontal span.
Teaching trig — show tan = sin/cos beside the dedicated helper.
Design system angles — keep brand angles in deg, convert to slopes once.
Fixed vs animated — use Sass when the angle is known; use CSS tan() when it must animate.
🧠 How Compilation Works
1
Write SCSS
Call math.tan($angle) after @use.
Source
2
Check angle units
Accept deg-compatible angles; treat unitless as radians.
Validate
3
Compute tangent
Return a unitless slope ratio (sin/cos for that angle).
Tan
4
✓
Plain CSS ships
The browser only receives the final number (or a length you rebuild).
Watch Out
⚠️ Common Pitfalls
Unitless ≠ degrees — bare numbers are radians; write deg when you mean degrees.
Passing lengths — math.tan(10px) fails; pass an angle, then multiply by a length.
Near 90° — tangent grows huge as cosine approaches zero; avoid for UI tokens.
Expecting an angle back — tangent is a ratio, not deg.
Old Dart Sass — need 1.25+; LibSass lacks the module API.
Pro Tips
💡 Best Practices
✅ Do
Use @use "sass:math" and math.tan() in new SCSS
Write deg (or rad) explicitly for clarity
Multiply by a run length when you need the rise in CSS
Keep design angles away from vertical (near 90°)
Prefer Dart Sass 1.25+
❌ Don’t
Assume unitless means degrees
Pass px / rem into math.tan
Expect the browser to re-evaluate math.tan
Use Sass tan for animated angles (prefer CSS tan())
Rely on LibSass for sass:math
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about math.tan()
Compile-time tangent—angles in, slope ratio out.
5
Core concepts
📝01
Call
math.tan($angle)
API
📦02
Module
sass:math
@use
🌡️03
Unitless
= radians
Rule
🔢04
Meaning
rise / run
Slope
⚡05
Since
Dart Sass 1.25+
Tooling
❓ Frequently Asked Questions
math.tan($number) returns the tangent of an angle. Example: math.tan(100deg) is about -5.6712818196; math.tan(1rad) and math.tan(1) are about 1.5574077247.
Add @use "sass:math"; then call math.tan($number). Requires Dart Sass 1.25+.
An angle compatible with deg (such as deg, rad, turn, grad), or a unitless number. Unitless values are treated as radians.
No. Tangent is a unitless ratio (rise over run). Multiply by a length if you need a CSS length, for example $run * math.tan(30deg).
Tangent is sin/cos. math.tan($a) matches math.sin($a) / math.cos($a) for the same angle (within floating-point precision). Prefer math.tan when you want the slope form.
Official docs expose this as math.tan() on sass:math. Prefer the module form with @use "sass:math".
Did you know?
Official Sass docs note that if $number has no units, it is assumed to be in rad. That is why math.tan(1) and math.tan(1rad) print the same value in the documentation examples.
math.tan() gives you compile-time tangent for known angles—ideal for slopes, ramps, and skew tokens. Prefer explicit deg or rad, remember that unitless means radians, and keep UI angles away from vertical extremes.