Sass math.tan() Function

Beginner
⏱️ 12 min read
📚 Updated: Jul 2026
🎯 5 Examples
sass:math · Dart Sass 1.25+

What You’ll Learn

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

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.

📝 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

ParameterTypeRequiredDescription
$numberNumberYesAn angle whose units are compatible with deg (e.g. deg, rad, turn, grad), or a unitless number treated as radians.

Return value

TypeSituationResult
NumberValid angle or unitless radianUnitless tangent (slope ratio)
ErrorIncompatible units (e.g. px)Compile fails—pass an angle, not a length

📦 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+.

📏 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.

CallResult (approx.)Notes
math.tan(100deg)-5.6712818196Official example
math.tan(1rad)1.5574077247Official example
math.tan(1)1.5574077247Unitless = radians
math.tan(0deg)0Flat slope
math.tan(45deg)1Rise equals run
120px * math.tan(30deg)~69.2820323pxRise from a known run
math.tan(10px)Error: not an angle

🛠 Compatibility

This is about Sass compilers, not browsers. Compiled CSS receives a plain number.

Implementationmath.tan()Notes
Dart Sass 1.25+YesPreferred; needs @use "sass:math"
Dart Sass < 1.25NoUpgrade Dart Sass
LibSass / Ruby SassNo module APIUse Dart Sass for trigonometric helpers

⚡ Quick Reference

GoalCode
Import math@use "sass:math";
Tangent in degreesmath.tan(100deg)
Tangent in radiansmath.tan(1rad) or math.tan(1)
Rise from a run$run * math.tan($angle)
Same as sin/cosmath.sin($a) / math.cos($a)
Debug while learning@debug math.tan(45deg);

📋 tan vs sin vs cos

FunctionWhat it returnsCommon use
math.tan($angle)Slope ratio (sin/cos)Ramps, skews, rise from a known run
math.sin($angle)Vertical / opposite factorY on a circle
math.cos($angle)Horizontal / adjacent factorX 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.

📋 Sass math.tan() vs CSS / JS tan

Sass math.tan()CSS tan() / JS Math.tan
When it runsCompile time (Dart Sass)In the browser / runtime
Appears in CSS output?No — only the numeric resultCSS tan() can stay in the stylesheet
Unitless inputTreated as radiansJS: radians; CSS: follows CSS angle rules
Best forFixed slopes known in SCSSDynamic angles, animated custom properties

Examples Gallery

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

📚 Getting Started

Official-style deg/rad calls and familiar slopes.

Example 1 — Basic math.tan()

Official docs examples with degrees and radians.

styles.scss
@use "sass:math";

@debug math.tan(100deg); // -5.6712818196
@debug math.tan(1rad);   // 1.5574077247
@debug math.tan(1);      // 1.5574077247

.demo {
  --tan-100deg: #{math.tan(100deg)};
  --tan-1rad: #{math.tan(1rad)};
}

How It Works

Degrees and radians are both valid angle inputs. Unitless 1 matches 1rad, not 1deg.

Example 2 — Common Angles

Memorize a few slopes: 0°, 30°, 45°.

styles.scss
@use "sass:math";

.landmarks {
  --t0: #{math.tan(0deg)};   // 0
  --t30: #{math.tan(30deg)}; // ~0.5773502692
  --t45: #{math.tan(45deg)}; // 1
}

How It Works

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)};
}

How It Works

Write deg when you mean degrees. Leaving units off is the same as writing rad.

📈 Practical Patterns

Ramp heights and sin/cos cross-checks.

Example 4 — Rise from a Known Run

Size a ramp or wedge: rise = run × tan(angle).

styles.scss
@use "sass:math";

$run: 120px;
$angle: 30deg;
$rise: $run * math.tan($angle);

.ramp {
  width: $run;
  height: $rise;
  --tan: #{math.tan($angle)};
}

How It Works

math.tan(30deg) ≈ 0.577. Multiplying by the horizontal run gives the vertical rise.

Example 5 — Same as sin / cos

Confirm that tangent matches the sine-over-cosine definition.

styles.scss
@use "sass:math";

$angle: 100deg;

.check {
  --tan: #{math.tan($angle)};
  --via-sin-cos: #{math.sin($angle) / math.cos($angle)};
}

How It Works

Both paths produce the official math.tan(100deg) result. Prefer math.tan when the slope form is clearer than writing the division yourself.

🚀 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).

⚠️ Common Pitfalls

  • Unitless ≠ degrees — bare numbers are radians; write deg when you mean degrees.
  • Passing lengthsmath.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.

💡 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

Key Takeaways

Knowledge Unlocked

Five things to remember about math.tan()

Compile-time tangent—angles in, slope ratio out.

5
Core concepts
📦 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.

Conclusion

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.

Continue with math.unit(), math.sin(), or math.atan().

More Sass Math

Continue with reading unit strings in the math module.

math.unit() →

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