Lesson 20 of 50
cssTransitions
9 mins
Course progress40%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 20 of 50
css9 mins
Keep these ideas in mind as you work through the lesson.
CSS transitions animate a property from its current state to a new state when a change occurs (usually a pseudo‑class trigger). They are perfect for micro‑interactions.
transition: <property> <duration> <timing‑function> <delay>;
property – Which CSS property to animate (all or a specific one). Not all properties are transitionable (e.g., display).duration – How long the animation runs (0.3s, 200ms).timing‑function – Controls the acceleration curve (ease, linear, cubic-bezier(), steps()).delay – Optional pause before the transition starts.a {
color:#0066cc;
text-decoration:none;
transition:color .2s ease, transform .2s ease;
}
a:hover {
color:#004499;
transform:translateY(-2px);
}
The link fades to a darker shade and nudges upward for a subtle gesture.
transform and opacity for any motion – they are handled by the compositor and stay 60 fps.will-change can hint the browser, but over‑using it forces the creation of a new layer, hurting performance. Use only when you know an element will animate.prefers-reduced-motion – turn off non‑essential transitions for users who disable motion.@media (prefers-reduced-motion: reduce) {
*, *::before, *::after { transition:none !important; }
}
background-color on MobileMobile browsers occasionally drop the transition due to power‑saving heuristics. Pair it with a fallback that still provides a visual cue (e.g., a subtle box‑shadow).