D DevBrainBox

CSS Transitions

CSS

What is a CSS Transition?

A CSS Transition lets you gradually change property values (like color, size, position) over time, instead of instantly.

selector {
  transition: property duration timing-function delay;
}

button {
  background-color: blue;
  transition: background-color 0.3s ease;
}
button:hover {
  background-color: green;
}

When you hover over the button, the background color fades smoothly from blue to green in 0.3 seconds.

PropertyWhat it does
transition-propertyWhich property to animate (color, width, all, etc.)
transition-durationHow long the animation lasts (0.5s, 200ms)
transition-timing-functionHow the speed changes (ease, linear, ease-in-out, cubic-bezier)
transition-delayWait before starting the transition

On this page