Sub topic 13
Inspecting and Debugging Motion in Browser Developer Tools
This chapter assumes you can write a basic transition and a @keyframes animation, and that you know how to open your browser's developer tools. The panel names below match Chrome and Edge. Firefox and Safari have similar tools with different labels.
Motion bugs are hard to see. An effect lasts 200 milliseconds, so you can't tell by looking whether a transition failed to start, ran with the wrong easing, or ran on a property that can't animate. Developer tools let you slow motion down, replay it, and read the exact values the browser used.
Why motion is hard to debug
Three things make animation bugs different from layout bugs:
- The effect is brief. By the time you notice a problem, it is over.
- The effect depends on state. A hover transition only exists while the pointer is over the element.
- The cause is often not in the animation rules. A different rule can win the cascade, the property may not be animatable, or the element may not change its computed value at all.
The tools address each of these. You can pause and slow time, force a state without holding the mouse, and read the computed result.
The Animations panel
In Chrome DevTools, open the command menu with Ctrl+Shift+P (Cmd+Shift+P on macOS) and run Show Animations. The panel is empty until the page runs a transition or animation. Once one runs, it appears as a group on a timeline.
Each group shows:
- A bar for each animated element, with its length proportional to duration and delay.
- The element it belongs to. Hover over a bar to highlight the element in the page.
- Keyframe points along the bar, shown as dots.
You can then do the following:
- Choose a playback speed of 100%, 25%, or 10%. At 10%, a 200 ms transition takes two seconds, which is long enough to see which property moves first.
- Click the timeline to scrub to any moment. The page shows the element at that point.
- Replay the group to run it again without repeating the user action.
- Drag the bar's handles to change duration or delay and see the effect live.
- Drag keyframe dots to change when a keyframe happens.
The panel edits are temporary. They don't change your stylesheet, so copy the values you like back to your source.
Forcing states without holding the mouse
A :hover rule only applies while the pointer is on the element. Moving the pointer into the Elements panel to inspect it removes the hover. Use the force-state tool instead.
- Select the element in the Elements panel.
- In the Styles pane, click :hov.
- Check
:hover,:focus,:focus-visible,:active, or another state.
The element now behaves as if it were in that state, and any transition runs. Untick the box to run the transition in reverse. Doing this for both directions is useful because the return trip uses the transition declared on the element's base rule, not the one on the :hover rule. If your hover rule sets a long transition and the base rule sets none, the element snaps back instantly. The force-state tool makes this easy to catch.
For class-based triggers, double-click the class attribute in the Elements panel and add or remove the class by hand. The browser starts a transition as soon as the computed value changes.
Reading computed values while motion runs
The Computed tab shows the current value of each property, and during an animation those values change on every frame. Select the element, open the Computed tab, and replay the animation at a slow speed. You can watch opacity or transform change.
This answers a common question: is the value changing at all? If the Computed tab shows the same background-color before and after you apply a class, no transition can start, because a transition needs a change in the computed value.
The Computed tab also lists the final values of transition-property, transition-duration, transition-timing-function, and transition-delay. Check these first when a transition does not behave as written. The shorthand can quietly produce values you did not intend, which the next section covers.
Common problems and how to find them
The table maps symptoms to causes and the check that confirms each one.
| Symptom | Likely cause | How to confirm |
|---|---|---|
| No motion at all | Property value did not change, or it is not animatable | Computed tab shows identical values before and after |
| Instant snap on hover-out | Transition declared only on the `:hover` rule | Force `:hover` off and read the transition values on the base rule |
| Only one property animates | `transition-property` lists only that property | Check `transition-property` in Computed |
| Animation does not play | `@keyframes` name misspelled, or `animation-duration` is `0s` | Styles pane shows the `animation-name` struck out or no matching `@keyframes` block |
| Element flashes before animating | Delay is set and no `backwards` fill mode | Scrub the timeline and look at the pre-start state |
| Element snaps back at the end | No `forwards` fill mode | Scrub to the end and watch the final jump |
| Animation overridden | A later or more specific rule wins | Styles pane shows the losing declaration with a line through it |
| Motion looks jerky | Property triggers layout or paint on each frame | Performance panel shows layout and paint work |
The shorthand resets values you did not write
The transition and animation shorthands reset every longhand they do not mention. A later transition shorthand replaces an earlier one entirely. Here is a case where the second rule removes the first one's duration:
.panel {
transition: opacity 300ms ease-out;
}
.panel.is-open {
transition: transform;
}The second rule sets transition-property: transform and resets the duration to 0s. When .is-open is applied, the transform changes instantly, and opacity no longer has a transition. In DevTools, select the element with the class applied and look at the Styles pane. You will see the first rule's transition struck out, and the Computed tab will show a duration of 0s.
Transitions that cannot start
A transition needs a start value and an end value that the browser can interpolate. Two cases commonly fail:
- Animating from
height: autoto a fixed height. The browser cannot interpolate betweenautoand a length, so the value jumps. The Computed tab shows a number only at the end. - Changing
displayfromnonetoblock. The element has no rendered start state, so there is nothing to transition from. This is the problem that@starting-styleaddresses.
In both cases, the Animations panel never shows a bar. A missing bar means no transition or animation started, so look at the values and not at the timing.
Inspecting keyframe animations
When an element has an animation-name, the Styles pane shows the matching @keyframes rule below the element's rules. You can edit keyframe values there and the page updates immediately.
For keyframe animations, check these points:
- The name in
animation-namematches the@keyframesname exactly, including case. animation-durationis greater than zero. The default is0s, so an animation with no duration does not run.animation-iteration-countis what you expect. A value ofinfinitekeeps the Animations panel busy, which can be useful for inspection.animation-fill-modematches what should happen before the start and after the end.animation-play-stateis notpaused.
The shorthand reads durations by position. The first time value is the duration and the second is the delay. If you write animation: pulse 1s 2s, the animation waits two seconds before running, and it can look like nothing happens.
Finding performance problems
Smoothness depends on which properties change. To check, record a trace.
- Open the Performance panel.
- Click record, trigger the motion, and stop recording.
- Look at the frames lane for dropped frames, shown in red.
- In the main thread lane, look for Recalculate Style, Layout, and Paint entries repeating on every frame.
If you see Layout on every frame, the animation is changing a property such as width, top, or margin. Switching to transform and opacity usually removes that work, because those properties can be handled by the compositor without running layout or paint.
DevTools has two more aids. The Rendering tab (open it from the command menu with Show Rendering) has Paint flashing, which highlights repainted regions in green. If a region flashes continuously during the animation, the animation is repainting. It also has Layout Shift Regions, which highlights shifts caused by layout changes.
Testing reduced motion
You do not need to change your operating system settings to check your prefers-reduced-motion rules. In the Rendering tab, find Emulate CSS media feature prefers-reduced-motion and set it to reduce. Then replay the interaction. Animations you disabled should no longer appear in the Animations panel, and the Computed tab should show animation-name: none for those elements.
Test both values, since a mistake in the media query can break the default behavior as well.
Debugging events from the console
When a script depends on transitionend or animationend, confirm that the event fires. Add temporary logging:
const target = document.querySelector('.button');
['transitionrun', 'transitionstart', 'transitionend', 'transitioncancel'].forEach((name) => {
target.addEventListener(name, (event) => {
console.log(name, event.propertyName, event.elapsedTime);
});
});The four events tell you what happened:
transitionrunfires when the transition is created, before any delay.transitionstartfires when the delay ends and the motion begins.transitionendfires when the motion completes.transitioncancelfires when the transition is interrupted, for example when the pointer leaves mid-way, or whendisplaybecomesnone.
If you see transitionrun and transitioncancel but never transitionend, something is interrupting it. Code that waits on transitionend alone will hang in that case, so handle cancel as well.
In the console you can also list running animations with the Web Animations API:
document.getAnimations().forEach((animation) => {
console.log(animation.id || animation.animationName || animation.transitionProperty, animation.playState);
});An empty array means nothing is running. This check is quick, and it works in any browser that supports getAnimations().
Exercises
Exercise
A card should fade in when the class is-visible is added. You add the class in DevTools and nothing animates, and the Animations panel shows no bar. The CSS is .card { opacity: 0; } .card.is-visible { opacity: 1; }. What is missing, and which DevTools tab confirms it?
Show answer
No transition is declared, for example transition: opacity 300ms ease-out on .card. The opacity value does change, so the Computed tab shows the new value, but transition-duration there reads 0s. That confirms the browser has no duration to animate over.
Exercise
A button grows on hover, but it snaps back instantly when the pointer leaves. Where is the transition declared, and how do you test the fix in DevTools?
Show answer
The transition is declared only on the :hover rule, so it applies only while hovering. The return trip uses the base rule, which has no transition. Move the transition declaration to the base .button rule. To test, select the button, click :hov, tick and untick :hover, and watch the Animations panel for a bar in both directions.
Exercise
You see transitionrun and transitioncancel in the console log but never transitionend. What does this tell you, and how should script code that waits for the end of the transition be written?
Show answer
Something interrupted the transition before it completed, such as the pointer leaving, a class being removed, or display: none being applied. Code that waits only for transitionend can hang. Listen for transitioncancel too, and run the same cleanup in both handlers.