Favorites

tan() CSS Function

tan()
CSS FunctionThis function is supported by all modern browsers.
Updated 21st November 2026

The tan() function returns the tangent of an angle.

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee

Description

The tan() CSS function calculates the tangent of an angle. The argument is an <angle> or a plain number (radians), and the result is a <number> that can range from negative to positive infinity. For example, tan(45deg) is 1, and the value grows very quickly as the angle approaches 90 degrees.

The tangent is the ratio of the opposite side to the adjacent side of a right-angled triangle. In CSS this is useful when you know an angle and one side of a shape and need the other side, for example to work out how tall a slanted edge must be to cut across a box at a given angle, or how far a skewed element shifts.

The tan() function is one of the CSS trigonometric functions, together with sin(), cos(), tan(), asin(), acos(), atan() and atan2(). Like calc(), it can be used anywhere a value of the matching type is accepted, and its arguments can contain full calculations, custom properties and the constants pi and e.

/* Height of a diagonal cut across a 300px wide banner at 10deg */
.banner::after {
  height: calc(tan(10deg) * 300px);  /* about 52.9px */
}

/* Offset needed to compensate for a skew */
.skewed {
  transform: skewX(-15deg);
  margin-left: calc(tan(15deg) * 2rem);
}

Interactive Demo

050px100px150px200px250px
Demo Code
HTML Code
<div class="demo-track">
	<div class="demo-element"></div>
</div>
<div class="demo-scale"><span>0</span><span>50px</span><span>100px</span><span>150px</span><span>200px</span><span>250px</span></div>
CSS Code
.demo-track {
	width: 300px;
	height: 36px;
	background: #f4f4f4 repeating-linear-gradient(90deg, #b0b0b0 0 1px, transparent 1px 50px);
	outline: 1px solid #c5c5c5;
}
.demo-scale {
	display: grid;
	grid-template-columns: repeat(6, 50px);
	width: 300px;
	font-size: 11px;
	color: #666;
}
.demo-element {
	height: 100%;
	background: linear-gradient(90deg, #f72585, #b5179e);
	width: calc(tan(30deg) * 150px);
}

Syntax

tan() = tan( <calc-sum> )

Values

  • <calc-sum>A calculation resolving to an <angle> or a <number> (interpreted as radians). The function returns a <number> between -∞ and +∞.

Example

<div class="wrap">
<h1>CSS tan() examples</h1>
<div class="card chart">
<div class="col"><div class="bar" style="--a: 15deg"></div><div class="label">tan(15deg)</div></div>
<div class="col"><div class="bar" style="--a: 30deg"></div><div class="label">tan(30deg)</div></div>
<div class="col"><div class="bar" style="--a: 45deg"></div><div class="label">tan(45deg)</div></div>
<div class="col"><div class="bar" style="--a: 60deg"></div><div class="label">tan(60deg)</div></div>
</div>
<p class="note">Each bar height is calc(tan(angle) * 80px).</p>
</div>
/* Base demo layout */
* { box-sizing: border-box; }

body {
margin: 24px;
font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
background: #f5f7fb;
color: #102a43;
}

.wrap {
max-width: 860px;
margin: 0 auto;
}

h1 {
font-size: 20px;
margin: 0 0 16px;
}

.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 16px;
}

.card {
background: #fff;
border-radius: 12px;
padding: 16px;
box-shadow: 0 6px 18px rgba(16, 42, 67, 0.08);
}

.label {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
font-size: 12px;
color: #486581;
margin-top: 10px;
word-break: break-word;
}

.note {
font-size: 13px;
color: #486581;
margin-top: 14px;
}

/* tan() examples */
.chart {
display: flex;
align-items: flex-end;
gap: 18px;
height: 200px;
padding-top: 10px;
}

.col {
flex: 1;
text-align: center;
}

.bar {
height: calc(tan(var(--a)) * 80px);
border-radius: 6px 6px 0 0;
background: linear-gradient(180deg, #f97316, #f59e0b);
}
Open in editor

Browser Support

The following information will show you the current browser support for the CSS tan() function. Hover over a browser icon to see the version that first introduced support for this CSS function.

This function is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee