Module 7 · Motion · Lesson 1 of 2

CSS Transitions

Advanced ⏱ 20 min2 sections · 1 exercise · 4-question quiz

A transition is animation between two states you already have — normal and hover, closed and open. Four sub-properties, one golden rule about what to animate, and your interfaces stop teleporting and start moving.

1. Anatomy of a transition

CSS — the pattern
.btn {
  background: #5A8AB9;
  transition: background .25s ease, transform .25s ease;
  /*          property   duration timing              */
}
.btn:hover {
  background: #3E6787;
  transform: translateY(-2px);
}

Declare the transition on the base state so it runs both directions. Name properties explicitly rather than all — intentional, and cheaper. A fourth value adds delay: transition: opacity .3s ease .1s.

2. Easing, and what's animatable

CSS — easing options
transition-timing-function: ease;          /* default, natural   */
transition-timing-function: ease-out;      /* fast start — best for UI */
transition-timing-function: linear;        /* mechanical         */
transition-timing-function: cubic-bezier(.68,-0.55,.27,1.55); /* overshoot! */

Only properties with in-between values animate: colors, opacity, transform, dimensions. display: none can't transition (nothing between none and block) — the classic fade uses opacity + visibility instead. Performance rule: prefer transform and opacity; they skip layout entirely.

💡 Craft custom curves by dragging handles in the Cubic Bezier editor — it previews the motion live and writes the function for you.

3. Try it yourself

The button snaps between states. Add transition: background .3s ease, transform .3s ease to .btn (not the hover!) and feel the difference.

exercise.html — editable

4. Quiz — check your understanding

CSS Transitions Quiz

4 questions · pass at 60%

Q1. Where should the transition be declared?

On the base state it animates both entering and leaving the hover.

Q2. Which property cannot be transitioned?

display has no intermediate values — there's nothing to interpolate.

Q3. The cheapest properties to animate are…

They're compositor-only: no layout or paint work per frame.

Q4. transition: opacity .3s ease .1s — the .1s is…

Duration comes first; the second time value is transition-delay.
🏆
Quiz passed? You're one step closer to your certificate.

Every lesson quiz you pass (60%+) is saved in your browser and counts toward the CSSmatic Certificate of Completion.

Track my progress →