π CSS Angle Units β deg & rad Explained
π What Are Angle Units in CSS?
CSS uses angle units to define rotation, direction, and orientation in various properties like transform, gradients, and animation. The two most commonly used units are:
- deg β Degrees (most human-friendly)
- rad β Radians (mathematically precise)
>>βAngles define how elements rotate, how gradients flow, and how animations turn.β
π¦ 1. deg β Degrees
deg (degree) is the most commonly used unit in CSS for rotations. A full circle is 360deg.
| Angle | Meaning |
|---|---|
| 0deg | No rotation |
| 90deg | Quarter turn clockwise |
| 180deg | Half turn |
| 360deg | Full rotation |
π§ͺ Example β Rotating an Element
rotate with degrees
.box {
transform: rotate(45deg);
}Rotates the box 45Β° clockwise.
π 2. rad β Radians
rad (radian) is a mathematical angle unit. A full circle is 2Ο radians (β 6.28318rad).
| Radians | Equivalent Degrees |
|---|---|
| 1 rad | β 57.296Β° |
| Ο/2 rad | 90Β° |
| Ο rad | 180Β° |
| 2Ο rad | 360Β° |
Note
rad is more common in math-heavy environments like JavaScript animations or SVG transformations.
π§ͺ Example β Rotating Using Radians
rotate with radians
.wheel {
transform: rotate(1.57rad); /* ~90deg */
}π¨ Where Are Angle Units Used?
- transform: rotate()
- transform: skew()
- gradients (linear, conic)
- offset-path
- motion-path animations
- clip-path (in some shapes)
π Examples of Angles in Real CSS Scenarios
1οΈβ£ Linear Gradient Direction
Gradient with angle
.gradient {
background: linear-gradient(45deg, #ff6, #f06);
}2οΈβ£ Conic Gradient
Conic gradient example
.pie {
background: conic-gradient(from 90deg, red, yellow, green, blue);
}3οΈβ£ Skew Transformation
Skew Example
.tilt {
transform: skewX(20deg);
}π§ Converting deg β rad
| Conversion | Formula |
|---|---|
| Degrees β Radians | rad = deg Γ Ο / 180 |
| Radians β Degrees | deg = rad Γ 180 / Ο |
Note
Useful if you're mixing CSS with JavaScript animations.
π Visual Guide
Imagine a clock:
- 3 o'clock β 0deg / 0rad
- 12 o'clock β 270deg / 4.71rad
- 6 o'clock β 90deg / 1.57rad
This helps visualize how CSS rotates elements.
β οΈ Common Mistakes
- β Using rad when degrees are easier (CSS prefers deg)
- β Forgetting deg in gradients β invalid property
- β Mixing clockwise (CSS) and counterclockwise (math) mental models
Note
π‘ Degrees (deg) are almost always the right choice for CSS styling. Use rad only when mathematically necessary.
π₯ Summary
CSS angle units deg and rad help create rotations, gradients, animations, and advanced UI effects. Degrees are more intuitive, while radians offer mathematical precision.
>>βUse deg for design. Use rad for math.β
Learn more β MDN Docs π