sin()
Example
.dot {
top: calc(sin(30) * 100px);
}.dot {
top: calc(sin(30deg) * 100px);
}A plain number is read as radians, so the 'deg' unit is needed to get the sine of 30 degrees, which is half.
Common mistakes
- Writing
sin(30)and getting the sine of 30 radians, not degrees. - Using
sin()as a length, which makes the declaration invalid.
Key points
- The angle argument has a unit like 'deg' or 'turn' unless radians are meant.
- The result is multiplied by a length inside
calc()before it is used as a position. - A fallback value comes first where trigonometric functions are unsupported.
Interview questions
Can I animate sin() in CSS?
Yes. Register the angle custom property with @property as an <angle>, then animate it, and sin() updates each frame.
What is the difference between sin() and asin()?
sin() takes an angle and returns a number from -1 to 1. asin() takes such a number and returns the angle.