Skip to the page
css reference · interaction & polish

CSS transition

type
property (shorthand)
applies to
any element with a property that changes
inherits
no
common values
opacity 0.2s ease, all 0.3s ease-in-out

Where it goes

On the tag in its normal state, not on the :hover rule.

Example

button {
  opacity: 1;
  transition: opacity 0.2s ease;
}
button:hover {
  opacity: 0.8;
}

Common mistakes

  • Putting transition inside the :hover rule. Then it only glides on the way in. When the mouse leaves, it snaps back.
  • Using transition: all as a catch-all. It can quietly animate things it should not, like layout sizes, and slow the page down.

Related

Updated 24 October 2026. Practice it in the css route, or read more on MDN.