How it works
Transitions are bookkeeping around style change events. For each element and longhand property the browser keeps at most one running transition and one completed transition. When style is recalculated:
- Before-change style is the computed style from the previous style change event, with running animations and transitions advanced to the current time.
- After-change style is the new computed style, without any transitions.
- For each longhand, the browser finds the matching
transition-property value (the last one in the list that matches), and through it the matching duration, delay, timing function and behaviour by list position.
- If there's no running transition, the values differ, they're transitionable, the completed transition (if any) didn't already end at this value, there's a matching entry, and duration plus delay is above zero, a new transition starts. Its start time is now plus the delay.
"Transitionable" means the animation type is neither "not animatable" nor "discrete", or, in Transitions 2, discrete with allow-discrete. Some pairs are discrete even when the property isn't: box-shadow between an inset and a non-inset shadow can't interpolate. Custom properties are discrete unless registered with a type through @property.
A running transition is a CSSTransition object, visible through element.getAnimations(). Its effect writes into the transitions origin of the cascade, which sits above even !important author rules; that's what lets a transition animate a value the author marked important. You can pause it and set currentTime, which is how the example inspects mid-flight values deterministically.
Starting style. An element that wasn't rendered in the previous style change event (just inserted, or coming from display: none) has no before-change style. If @starting-style rules match it, the browser computes a starting style (after-change style plus those rules) and compares that instead. The rules inherit from the parent's after-change style and don't win by position: they cascade normally, so a more specific rule outside @starting-style can override them.
Discrete values. With allow-discrete, a discrete property's transition holds the start value until 50% progress and then switches. In Chrome 156 and Firefox 159, text-align: left to right over a 1s linear transition read left at 400ms and right at 600ms. display borrows the rule visibility already has: for progress strictly between 0 and 1, the interpolated value is the visible one. That gives "visible for the whole duration" in both directions, and CSS Display 4 makes the element inert while its real value is none.
Events. Four events report a transition's lifecycle: transitionrun when it's created (still in its delay), transitionstart when the delay ends, transitionend when it completes and transitioncancel when it's removed early. Each carries propertyName and elapsedTime. They're dispatched at animation-frame time, not synchronously.
Edge cases
Reversing. Toggling a hover state back halfway shouldn't take the full duration to return. When a running transition's end value no longer matches but the new after-change value equals its start value, the browser starts the reverse transition with a reversing shortening factor that scales duration by how much of the first transition completed:
box.classList.add("wide"); // width 100px → 200px over 1s linear
const [first] = box.getAnimations();
first.pause();
first.currentTime = 250; // width is 125px
box.classList.remove("wide");
const [second] = box.getAnimations();
console.log(second.effect.getComputedTiming().duration);
// → 250
Chrome 156 and Firefox 159 agreed; first was cancelled (playState idle).
Cancellation. The browser cancels a running transition when the property drops out of transition-property (including transition: none, which jumps straight to the end value), when the element stops being rendered (display: none) or leaves the document. Cancellation fires transitioncancel only if the transition had already dispatched events. For one started and cancelled in the same task, before any frame, Chrome 156 still fired transitioncancel and Firefox 159 fired nothing; Firefox follows the event-dispatch table, where an idle to idle phase change dispatches nothing. The table guarantees exactly one transitionend or transitioncancel per transitionrun, so pair cleanup with transitionrun rather than with the class change.
Delay-only transitions. transition: width 0s 0.1s is valid and creates a CSSTransition (one entry in getAnimations() in both browsers), so the value jumps after 100ms.
Inherited properties. One change can start transitions on an ancestor and a descendant at once; the completed-transitions set exists so a child with a shorter duration doesn't keep restarting while the parent's transition is still feeding it new values.
Intrinsic sizes. height: auto isn't interpolable. Chrome 129 added interpolate-size: allow-keywords (and calc-size()); Firefox 159 doesn't support it, so plan a fallback.
Real-world scenario
A toast or menu built on the popover API needs an entry and exit fade. Exiting a popover removes it from the top layer, which would otherwise clip the fade and stack it under the page, so overlay joins display in the discrete list:
[popover] {
opacity: 1;
transition: opacity 0.2s, display 0.2s allow-discrete, overlay 0.2s allow-discrete;
}
[popover]:not(:popover-open) { opacity: 0; }
@starting-style { [popover]:popover-open { opacity: 0; } }
After hidePopover() in Chrome 156, :popover-open no longer matched, but transitions for display, opacity and overlay were running; halfway through, display was block, opacity 0.5, and overlay still auto. Firefox 159 doesn't support overlay and started no transition on hide, so the popover vanished at once while the entry fade still worked. That degrades acceptably, so the pattern needs no fallback. The same shape works for <dialog> with [open].
Trade-offs
Transitions suit state changes: one start and one end value, triggered by a class, attribute or pseudo-class, with reversing for free. They can't loop, run without a trigger, or pass through intermediate keyframes; that's @keyframes. They also restart from wherever the value is, which keyframe animations don't, so interrupted hover effects look smooth.
@starting-style plus allow-discrete replaces the old pattern of removing display: none, forcing a reflow with offsetWidth, then adding the class. The CSS version is declarative and runs in the browser's normal style pass, but its exit half depends on display transitions, which Firefox 159 doesn't do yet; design so a cut is acceptable.
Which properties are cheap to animate is a rendering question (opacity and transform usually avoid layout), covered in the web-performance topic; honouring prefers-reduced-motion belongs to the accessibility topic.