:hover).transform, opacity, background-color, color, etc.background-color, transform).0.3s, 500ms).ease: Default smooth curve.linear: Constant speed.ease-in: Starts slow, ends fast.ease-out: Starts fast, ends slow.ease-in-out: Slow at start and end.cubic-bezier(): Custom curve.transition property instead of writing all four separate properties.
/* Shorthand syntax for CSS transitions */
selector {
transition: property duration timing-function delay;
}
Examples of valid shorthand values:
/* Transition only background-color over 0.3s */
button {
transition: background-color 0.3s ease-in-out;
}
/* Transition multiple properties together */
.card {
transition: transform 0.4s ease, box-shadow 0.4s ease;
}
The timing function controls how the speed of the animation changes from start to end.
| Timing Function | Description | Typical Use Case |
|---|---|---|
ease |
Default smooth effect | General UI animations |
linear |
Constant speed from start to end | Progress bars, loaders, timers |
ease-in |
Starts slow, finishes fast | Elements entering the screen |
ease-out |
Starts fast, ends slowly | Elements leaving or fading out |
ease-in-out |
Slow at start and end | Buttons, cards, smooth hover effects |
Hover over the square box below to see the background color and size animate smoothly.
tomato).:hover, the background changes to dodgerblue and the box scales up.
/* Basic transition on background and scale */
.box {
width: 100px;
height: 100px;
background-color: tomato;
transition-property: background-color, transform;
transition-duration: 0.5s;
transition-timing-function: ease;
transition-delay: 0s;
}
.box:hover {
background-color: dodgerblue;
transform: scale(1.2);
}
This example uses the shorthand transition to animate both box-shadow and transform for a floating effect.
When you hover the card, it smoothly lifts up and casts a stronger shadow, creating a floating effect that feels responsive and modern.
/* Card that smoothly lifts on hover */
.card {
width: 200px;
height: 150px;
background: #fafafa;
border: 1px solid #ddd;
border-radius: 10px;
transition: box-shadow 0.3s ease-in-out, transform 0.3s ease-in-out;
}
.card:hover {
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
transform: translateY(-10px);
}
transition: all only for quick prototypes. In production, specify exact properties (for example, transition: transform 0.3s ease;).transform and opacity for better performance.0.15s and 0.5s for small UI interactions so the interface still feels fast.cubic-bezier() when you need a custom feel (for example, snappy or bouncy animations).transition.transition-delay to delay a hover effect and see how it affects UX.opacity from 0.5 to 1 on hover for a subtle fade-in effect.transform: translateX() with a smooth transition.ease, ease-in-out, and a custom cubic-bezier() curve for the same animation and compare the feel.