Sass math.tan()

Beginner
9 min read
Updated: Nov 2026
5 examples
Dart Sass 1.25+

Definition and Usage

math.tan($number) returns the tangent of $number. Pass an angle whose units are compatible with deg, or a unitless number treated as radians. The result is a unitless ratio (rise over run / slope). Load it with @use "sass:math" on Dart Sass 1.25+.

Official samples.

math.tan(100deg) → -5.6712818196 · math.tan(1rad) → 1.5574077247 · math.tan(1) → 1.5574077247.

Compile-time tangent.

Sass writes a fixed number into CSS. For dynamic angles (custom properties, animations), prefer CSS tan() in supporting browsers.

Unitless means radians.

math.tan(1) is not “1 degree” — it matches math.tan(1rad). Pass deg explicitly when you think in degrees.

Syntax

SCSS
@use "sass:math";

math.tan($number); //=> unitless number

math.tan(100deg); // -5.6712818196
math.tan(1rad);   // 1.5574077247
math.tan(1);      // 1.5574077247  (unitless = radians)

math.tan(0deg);   // 0
math.tan(45deg);  // 1

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

Pattern: choose an angle unit → call math.tan → multiply by a run length when you need CSS rise. Pair with math.sin, math.cos, and math.atan.

Angles and Units

How inputs are interpreted:

InputMeaningExample result
100degDegrees-5.6712818196
1radRadians1.5574077247
1 (unitless)Treated as radians1.5574077247
0degTangent of zero0
45degUnit slope1
30degFamiliar slope0.5773502692
Lengths like pxNot an angleError
Result is not an angle.

Tangent is a unitless slope. Need a length? Multiply: $run * math.tan(30deg). Same idea as math.div(math.sin($a), math.cos($a)).

SCSS Examples

Examples target Dart Sass 1.25+ with @use "sass:math". Open View Compiled CSS for verified output (matches official Sass docs samples).

Example 1 — Official Docs Sample (Degrees)

Tangent of 100deg is a large negative slope.

SCSS
@use "sass:math";

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

.basic {
  --deg: #{math.tan(100deg)};
}

How It Works

  1. Input is 100deg — an angle unit.
  2. Tangent returns a unitless number.
  3. Value is negative past 90deg in this quadrant.
  4. Matches the official Sass docs sample.

Example 2 — Radians and Unitless

Official samples: 1rad and unitless 1 match.

SCSS
@use "sass:math";

@debug math.tan(1rad); // 1.5574077247
@debug math.tan(1);    // 1.5574077247

.rad {
  --rad: #{math.tan(1rad)};
  --unitless: #{math.tan(1)};
}

How It Works

  1. 1rad is one radian.
  2. Unitless 1 is treated the same way.
  3. Both compile to 1.5574077247.
  4. Do not confuse unitless input with degrees.

Example 3 — Cardinal Angles

Familiar tangents for 0° and 45°.

SCSS
@use "sass:math";

.angles {
  --zero: #{math.tan(0deg)};
  --forty-five: #{math.tan(45deg)};
}

How It Works

  1. tan(0deg) → 0.
  2. tan(45deg) → 1 (equal rise and run).
  3. Handy as sanity checks for slope tokens.
  4. Avoid odd multiples of 90deg where cosine is zero.

Example 4 — Same as sin / cos

Tangent matches math.div(math.sin, math.cos) for the same angle.

SCSS
@use "sass:math";

.compare {
  --tan: #{math.tan(30deg)};
  --via-sin-cos: #{math.div(math.sin(30deg), math.cos(30deg))};
}

How It Works

  1. math.tan(30deg) is the slope form.
  2. math.div(sin, cos) matches within floating-point precision.
  3. Prefer math.tan when you want that intent.
  4. Use math.div instead of / for division.

Example 5 — Emit a Fixed CSS Ratio

Store a compile-time tangent for slope or skew helpers.

SCSS
@use "sass:math";

$angle: 100deg;

.wave {
  --t: #{math.tan($angle)};
  opacity: math.tan(0deg);
}

How It Works

  1. Angle token is resolved at compile time.
  2. Custom property receives the unitless tangent.
  3. opacity: 0 comes from tan(0deg).
  4. Keep CSS tan() when the angle must stay dynamic.

Edge Cases & Pitfalls

Most tan bugs are treating unitless input as degrees, or hitting near-vertical angles.

rad

Unitless = radians

math.tan(45) is not one. Write 45deg when you mean degrees.

return

Result is unitless

Multiply by a run length for CSS rise. Tangent itself is not deg.

90deg

Near-vertical angles

Tangent blows up when cosine approaches zero (odd multiples of 90deg). Prefer safer angles for layout math.

module

Module-only helper

Use math.tan after @use "sass:math".

Sass Support

Prefer the module form with Dart Sass 1.25+.

APIStatus
math.tan()Dart Sass 1.25+ via @use "sass:math"
InputAngle (deg-compatible) or unitless radians
Return typeUnitless number
LibSass / Ruby SassNo modern sass:math tan

Compile with the Dart Sass CLI.

Key Takeaways

  • Returns tangent as a unitless slope from an angle.
  • Unitless input = radians; prefer explicit deg when needed.
  • Same idea as sin/cos — prefer math.tan for slope intent.
  • Dart Sass 1.25+ via @use "sass:math".

One line: when an angle must become a fixed slope ratio in CSS, call math.tan($number).

Compile Notes

Practical checklist:

checklist.txt
1. @use "sass:math"
2. Pass deg-compatible angle or unitless radians
3. Expect a unitless slope ratio
4. Multiply by a run length when you need CSS rise
5. Use CSS tan() for runtime angles

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.div(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".

Next: Sass math.unit()

Inspect a number’s units as a string for debugging.

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.

8 people found this page helpful