CSS Transition Duration
The transition-duration property is the heartbeat of CSS animations. It dictates how long a transition effect takes to complete. Without it, property changes happen instantaneously, which can feel jarring to the user.
Time Units
CSS uses two primary units for measuring time in transitions:
- Seconds (s): The standard unit.
1s,0.5s. - Milliseconds (ms): Used for finer control.
1000msequals1s.500msequals0.5s.
User Experience
Choosing the right duration is critical. A duration that is too short (e.g., 50ms) might be unnoticeable, while one that is too long (e.g., 3s) makes the interface feel sluggish. A "sweet spot" for UI elements is usually between 200ms and 500ms.
Best Practices
Always specify the unit. Writing transition-duration: 2 is invalid CSS. Additionally, you can define multiple durations (e.g., 0.5s, 1s) to match the order of properties defined in transition-property.
