Trigonometric functions.
Trigonometric calculation functions.
The CSS specification now provides for many calculation functions, including trigonometric calculations. These are interesting for calculating the parameters of a transformation (rotation, scaling, etc.).
Typical trigonometric functions: cos()
- sin()
- tan()
Inverse trigonometric functions: acos()
- asin()
- atan()
- atan2()
.
It may also be useful to refer to the page on the CSS angle units.
These features can be used with:
The sin()
, cos()
, and tan()
functions can be used with all the properties that are waiting
a unitless numerical value.
The asin()
, acos()
, atan()
, and atan2()
functions can be used with all
properties that expect an angular value.
Syntax of trigonometric calculation functions.
- <propriété>: sin(30deg); a
Calculate the sine of
a
. The valuea
must be followed by a unit of angle.
The result is a unitless value, between-1
and1
.Some remarkable values:
sin(0)
is0
sin(30deg)
is0.5
sin(90deg)
is1
- <propriété>: cos(30deg); a
Calculate the cosine of
a
. As with the previous function, the valuea
must be followed by a unit of angle.
The result is a unitless value, between-1
and1
.Remarkable values :
cos(0)
is1
cos(60deg)
is0.5
cos(90deg)
is0
- <propriété>: tan(45deg);
Calculate the tangent of
a
. As with the previous functions, the valuea
must be followed by a unit of angle. The result is a unitless value, between-infinity
and+infinity
.Remarkable values:
tan(0)
is0
tan(45deg)
is1
tan(90deg)
isinfinity
- <propriété>: asin(0.253); n
Calculates the arc sine of
n
, which means thatasin()
finds the angle from the value of its sine, i.e. performs the inverse calculation ofsin()
. Thevalue n
must be a unitless number, between-1
and1
.
Ifn
is less than-1
or greater than1
, the result will beNaN
(Not a Number).The angle calculated by the function is expressed in radians and is between
-1.5708rad
and1.5708rad
, i.e., in degrees:-90deg
and90deg
. - <propriété>: acos(0.124); n
The function
acos(n)
calculates the cosine arc ofn
:acos()
finds the angle from the value of its cosine, i.e. performs the inverse calculation ofcos()
. Thevalue n
must be a unitless number, between-1
and1
.The calculated angle is expressed in radians and is in the range between
0rad
and3.14159rad
, which corresponds in degrees to the range from0
to180deg
. - <propriété>: atan(2.212); n
atan(n)
calculates the tangent arc ofn
, i.e. finds the angle from the value of its tangent:atan()
performs the reverse calculation oftan()
.
n
must be a number without units.The result is expressed in radians, and is in the range of
-1.5708rad
to+1.5708rad
or in degrees, from-90deg
to+90deg
. - <propriété>: atan2(125px, 150px); y x
Calculates the angle between the x-axis and a point at
the x
andy
coordinates.
x
andy
can be unitless numbers, percentages, or numbers followed by a dimension unit. These different possibilities cannot be mixed: the two values must be expressed in the same unit.The result is expressed in radians, and is in the range of
-3.14159rad
to+3.14159rad
, or in degrees, from-180deg
to+180deg
.The calculation performed by
atan2(y,x)
is equivalent toatan(y/x)
but the results of these two expressions can However, be different whenx
and/ory
have negative values or whenx
is0
.x
y
atan(y/x)
atan2(y,x)
1
1
0,785rad
(45deg)0,785rad
(45deg)1
-1
-0,785rad
(-45deg)-0,785rad
(-45deg)-1
1
-0,785rad
(-45deg)2,35rad
(135deg)-1
-1
0,785rad
(45deg)-2,35rad
(-135deg)0
1
Error
1,57rad
(90deg)
Simulator.
To maintain type compatibility, the trigonometric functions sin()
, cos()
, and tan()
are used
with the scale
property, while inverse trigonometric functions, which return an angle, are used with the rotates
property.
The predefined value pi
(180 degrees) is also present, as an example. Notice that cos(pi)
returns -1
.
When scaled this value causes the element to flip.
scale: 1
rotate: 0deg
Browser compatibility and support.
Trigonometric calculation functions are now well handled by all current browsers.
cos()
function
sin()
function
tan()
function
acos()
function
asin()
function
atan()
function
atan2()
function
Browsers on computers :
Mobile browsers :
Outdated or marginal browsers :

Internet Explorer

Baidu Browser

QQ Browser

Opéra Mobile

Firefox

Chrome

Safari

Edge

Opéra

Chrome pour Androïd

Safari sur IOS

Samsung Internet

UC Browser pour Androïd

Androïd Brower

Firefox pour Androïd

KaiOS Browser

Opéra mini
History of trigonometric functions.
-
CSS Values and Units Module Level 4
Trigonometric calculation functions are introduced in this level 4 of the specification.August 14, 2018Working Draft.
See also: Other calculation functions.
The calculation functions available in CSS are more and more numerous. They cover common mathematical and trigonometric calculations. For a more detailed description of these functions, you can refer to the W3C specification CSS Values and Units Module.
Functions:









Values:

e
(the basis of natural logarithms), which is approximately 2.7182818284590452354.


pi
(about 3.1415926535897932).