CSS transition: compare duration, delay, and easing
CSS transition displays intermediate values over time when a property’s computed value changes. This example changes the box’s transform and background-color when you check or uncheck a checkbox.
Read the property, timing, and easing settings
| Setting | Role and example |
|---|---|
transition-property |
The property to transition, such as transform or background-color. |
transition-duration |
The time the change lasts. 0.8s is 800ms. |
transition-timing-function |
The progress curve. Linear advances evenly, while ease varies the rate. |
transition-delay |
The start offset. Positive values wait, and negative values start partway through. |
transition-behavior |
The default is normal. Allow-discrete permits transitions of supported discrete properties. |
In transition: transform 0.8s ease 0.3s, transform waits 0.3 seconds, then changes over 0.8 seconds. The first time is the duration and the second is the delay. Separate entries with commas and name the intended properties to avoid transitioning unrelated changes with all. See CSS Transitions · Shorthand.
Try the checkbox-controlled transition
Save the code as transition.html and open it. Click the checkbox or use Tab to focus it and Space to toggle it. No JavaScript or external files are needed.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Try a checkbox-controlled transition</title>
<style>
body { margin: 20px; font: 16px/1.6 system-ui, sans-serif; color: #203348; }
* { box-sizing: border-box; }
h1 { font-size: 24px; }
label { display: inline-block; padding: 10px 4px; }
.stage { max-width: 500px; margin-top: 16px; padding: 12px;
border: 1px solid #8fa6ba; background: #edf3fa; }
.box { display: grid; place-items: center; width: 80px; height: 80px;
color: white; background-color: #1768a5; transform: translateX(0);
transition: transform 0.8s ease, background-color 0.8s linear; }
#move:checked ~ .stage .box { transform: translateX(150px); background-color: #087b76; }
@media (prefers-reduced-motion: reduce) {
.box { transition: none; }
}
</style>
</head>
<body>
<h1>Compare transition states</h1>
<input id="move" type="checkbox">
<label for="move">Move the square to the right</label>
<div class="stage"><div class="box">Box</div></div>
<p>Check to move and change color. Uncheck to return to the starting state.</p>
</body>
</html>
Checking the box shifts the square 150px to the right and changes its color from blue to teal. If reduced motion is off and the transition runs uninterrupted, both changes reach their targets in 0.8 seconds. The ease movement and the linear color change progress at different rates.
Compare delay, duration, and easing
Add transition-delay: 0.5s right after the shorthand in the base .box rule. Both changes wait half a second. Replace it with -0.4s. The 0.8-second transition starts 0.4 seconds into its timeline, so an intermediate state appears immediately. With ease, halfway through the time may not mean halfway across the distance. Remove the declaration afterward.
Add transition-duration: 2s in the same place to make both changes last two seconds. Remove it, then swap only the ease for linear in the transform entry. This isolates the timing curve while keeping the distance and duration fixed. Restore the original curve when done.
Troubleshoot missing or one-way transitions
The transition is on the base .box rule, so it also applies when you uncheck the box. If you only declare it in the checked state, the return can snap back. Reversing while a transition is running can continue from the current visible value and shorten the reversal. See CSS Transitions · Starting Transitions.
If there is no visible transition, inspect the starting and ending computed values, the property being transitioned, and whether the duration is greater than zero. With prefers-reduced-motion: reduce, the example uses transition: none. The position and color still update, but there is no intermediate movement. See Media Queries · Reduced Motion.




