No Login Data Private Local Save

CSS sin(), cos(), tan() Demo - Online Animated Trig

7
0
0
0

CSS sin(), cos(), tan() Live Demo

Interactive visualization of CSS trigonometric functions with real-time animation

Chrome 111+ Firefox 108+ Safari 15.4+
0Β° β€” sin: 0.000
CSS sin()/cos() Live Demo β€” circular layout using CSS trigonometric functions
Parameters
Live Values
Current Angle: 0Β°
sin(ΞΈ): 0.000
cos(ΞΈ): 1.000
tan(ΞΈ): 0.000
Generated CSS Code

CSS sin()/cos()/tan() are widely supported in all modern browsers (2023+)

Frequently Asked Questions

These are CSS mathematical functions introduced in CSS Values Level 4. They compute trigonometric values directly in CSS, accepting angle parameters (deg, rad, grad, turn) and returning unitless numbers. For example, sin(30deg) returns 0.5. They're typically used inside calc() expressions for layout calculations, animations, and positioning.
Chrome 111+ (March 2023), Firefox 108+ (Dec 2022), Safari 15.4+ (March 2022), and Edge 111+. As of 2025, global coverage exceeds 95%. These functions are safe for production use with appropriate fallbacks.
The key difference: CSS sin()/cos()/tan() accept angles (with explicit units like deg, rad), while JavaScript's Math.sin() expects radians. In CSS, sin(90deg) = 1 is intuitive. In JS, you'd need Math.sin(Math.PI / 2). CSS functions also integrate seamlessly with calc() and CSS custom properties.
  • Circular layouts β€” position elements around a center point
  • Oscillating animations β€” smooth back-and-forth motion
  • Wavy decorations β€” sinusoidal borders or backgrounds
  • Radial menus β€” arrange nav items in a circle
  • Orbital effects β€” elements orbiting a central point
  • Dynamic spacing β€” angle-based responsive calculations
You need to use @property to register a custom property that can be interpolated, then animate it with @keyframes. Example: register --angle as a <angle> type, animate from 0deg to 360deg, and use transform: translate(calc(sin(var(--angle)) * 100px), calc(cos(var(--angle)) * 100px)) for circular motion.
tan() has asymptotes at 90Β°, 270Β°, etc., where it approaches Β±infinity. In CSS, tan(90deg) returns an extremely large value (β‰ˆ 1.63Γ—10¹⁢ in practice). This can cause layout overflow or elements to disappear off-screen. Always constrain tan() values with clamp() or ensure your angles stay within safe ranges (e.g., -45Β° to 45Β°).
Yes! You can freely mix them: calc(sin(var(--a)) * 100px + cos(var(--b)) * 50px). This is powerful for creating complex motion paths. For circular motion, use sin() for X and cos() for Y (or vice versa depending on starting position). The functions return plain numbers, so multiply by a length unit to get usable CSS values.
All CSS angle units: deg (degrees), rad (radians), grad (gradians, 400 per circle), and turn (full rotations). Example: sin(0.5turn) = 0, sin(3.1416rad) β‰ˆ 0, sin(180deg) = 0. Use whichever unit fits your mental model best!
Key Concepts
sin() for Oscillation

sin(ΞΈ) oscillates between -1 and 1, making it perfect for smooth back-and-forth animations, bouncing effects, and wave patterns in CSS.

cos() for Phase Shift

cos(ΞΈ) = sin(ΞΈ + 90Β°). It's identical to sin but shifted by 90Β°. Use cos() when you need an element to start at maximum displacement rather than zero.

tan() Caution

tan(ΞΈ) = sin(ΞΈ)/cos(ΞΈ). It has vertical asymptotes where cos(ΞΈ)=0 (90Β°, 270Β°). Use with care and consider wrapping in clamp() for safety.