The sin()
CSS function is a trigonometric function that returns the sine of a number, which is a value between -1
and 1
. The function contains a single calculation that must resolve to either a <number>
or an <angle>
by interpreting the result of the argument as radians. That is, sin(45deg)
, sin(0.125turn)
, and sin(3.14159 / 4)
all represent the same value, approximately 0.707
.
sin()
Baseline 2023
Newly available
Since March 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
Syntax
/* Single <angle> values */ width: calc(100px * sin(45deg)); width: calc(100px * sin(0.25turn)); width: calc(100px * sin(1.0471967rad)); /* Single <number> values */ width: calc(100px * sin(63.673)); width: calc(100px * sin(2 * 0.125)); /* Other values */ width: calc(100px * sin(pi / 2)); width: calc(100px * sin(e / 4));
Parameters
Return value
The sine of an angle
will always return a number between −1
and 1
.
- If
angle
isinfinity
,-infinity
, orNaN
, the result isNaN
. - If
angle
is0⁻
, the result is0⁻
.
Formal syntax
Examples
Changing box sizes
In this example, sin(30deg)
will return 0.5
, making the box have a 50px
width and a 50px
height.
div { background-color: red; width: calc(sin(30deg) * 100px); height: calc(sin(30deg) * 100px); }
Controlling animation duration
Another use case is to control the animation-duration
, reducing the duration based on the sine value. In this case, the animation duration will be 1s
.
div { animation-name: myAnimation; animation-duration: calc(sin(0.25turn) * 1s); }
Specifications
Specification |
---|
CSS Values and Units Module Level 4 # trig-funcs |
Browser compatibility
Desktop | Mobile | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | |
sin |
111 | 111 | 108 | 97 | 15.4 | 111 | 108 | 75 | 15.4 | 22.0 | 111 |
See also
© 2005–2024 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/sin