Nearby lessons

9 of 15

πŸ”„ CSS Transitions

πŸ“Œ What are CSS Transitions?

CSS transitions allow smooth animation between changes in CSS properties. Instead of abrupt changes, transitions let properties animate over time.

  • πŸ”Έ transition - Shorthand property for all transition properties
  • πŸ”Έ transition-property - Specifies which property will animate
  • πŸ”Έ transition-duration - Defines how long the animation takes
  • πŸ”Έ transition-timing-function - Controls animation speed curve
  • πŸ”Έ transition-delay - Delays the start of the transition

πŸ”Ή Basic Transition

A simple example animating width and height on hover.
Example02
✨Code Cell
Loading Editor...
✏️ You can edit this code β€” click Run to refresh the preview.
Output

πŸ”Ή Shorthand Transition

Use transition: all 2s ease-in-out to animate all properties at once.
Example03
✨Code Cell
Loading Editor...
✏️ You can edit this code β€” click Run to refresh the preview.
Output

πŸ”Ή Timing Function: ease-in-out

Applies a slow start and end. This improves user experience with subtle easing.
Example04
✨Code Cell
Loading Editor...
✏️ You can edit this code β€” click Run to refresh the preview.
Output

πŸ’‘ Transition Best Practices

  • βœ… Keep transitions under 300ms for responsiveness
  • βœ… Limit the number of transitioned properties
  • βœ… Avoid transitioning layout-affecting properties like top/left if possible
  • βœ… Use cubic-bezier() for custom easing
  • βœ… Provide reduced-motion options for accessibility

🧠 Test Your Knowledge

5 Questions
Progress: 0 / 5