tan() CSS Function
The tan() function returns the tangent of an angle.
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
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
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.
Desktop





Tablets & Mobile





