sin()

Term side of the Card.
Topic: Mathematics
Unit title: sin()
Categories: Function
Explanation side of the Card

Explanation: The math function that returns the sine of an angle, typically used within `calc()` to perform trigonometric calculations. This function can help create advanced geometrical effects or animations based on sinusoidal wave patterns.

Browser compatibility:
  • The chrome browser supports this feature starting from version 111.
  • The edge browser supports this feature starting from version 111.
  • The firefox browser supports this feature starting from version 108.
  • The safari browser supports this feature starting from version 15.4.
Availability: 

Example

Wrongcss
.dot {
  top: calc(sin(30) * 100px);
}
Rightcss
.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.

Analytics cookiesWe'd like to use analytics cookies to see which pages are useful. They're set only if you accept. Privacy Policy