Sub topic 10
Specifying interactions and motion
This chapter assumes you can build components in a design tool such as Figma, and that you know basic CSS. It also assumes you have already documented component states (default, hover, focus, active, disabled, loading, error, empty). Interactions and motion describe what happens between those states. A developer can see two frames in your file, but the frames don't tell them how the change should happen, how long it takes, or what triggers it.
Why motion needs a spec
A static state list answers "what does the button look like when hovered?" It does not answer these questions:
- What triggers the change: pointer, keyboard, touch, or a timer?
- How long does the change take?
- Which properties change, and which stay fixed?
- What easing does the change use?
- What happens if the user interrupts it halfway?
- What happens for people who have asked their system to reduce motion?
If the handoff leaves these out, the developer picks values. Two developers will pick different values. The result is an interface that feels inconsistent even when every state matches the design.
Prototype links in a design tool are a useful demonstration, but they are not a spec. A prototype shows one path through the design. It usually hides timing details, and a developer cannot reliably read an easing curve from a recording.
What to specify for each interaction
For each interaction, write down five things.
- Trigger. The event that starts it, such as hover, focus, click, key press, scroll position, or page load.
- Target. The element or elements that change.
- Properties. The exact properties that animate, such as
background-color,transform, oropacity. - Timing. Duration, delay, and easing.
- End state. The state the element reaches, and whether it stays there or returns.
A compact table in the annotation next to the component keeps this readable:
| Interaction | Trigger | Properties | Duration | Easing |
|---|---|---|---|---|
| Button hover | pointer enters | background-color | 150 ms | ease-out |
| Menu open | click on toggle | opacity, transform (translateY) | 200 ms | ease-out |
| Menu close | click outside, Esc | opacity | 120 ms | ease-in |
| Toast enter | on error | opacity, transform (translateY) | 250 ms | ease-out |
Notice that closing is faster than opening in this table. That is a common pattern. Elements that appear in response to a user action can take a little longer, because the user is waiting to see them. Elements that leave should get out of the way quickly.
Choosing durations
You don't need to calculate durations from a formula. You do need to choose from a small, consistent set. A reasonable starting range for web interfaces:
| Kind of change | Typical duration |
|---|---|
| Small color or opacity change (hover) | 100 to 150 ms |
| Small element moving or appearing (menu, tooltip) | 150 to 250 ms |
| Large element or full-panel change (drawer, modal) | 250 to 400 ms |
Very short changes under about 100 ms read as instant. Changes over about 500 ms start to feel slow in everyday UI, because the user is waiting for the interface to catch up. Treat these numbers as defaults to adjust, not rules. Test them in the real build.
Easing in terms a developer can use
Easing describes how speed changes over the duration. "Smooth" is not a spec. Name the curve in a form that maps to CSS.
ease-outstarts fast and slows down. Use it for elements entering the screen or responding to the user.ease-instarts slow and speeds up. Use it for elements leaving the screen.ease-in-outstarts and ends slowly. Use it for elements that move from one place to another on screen.linearkeeps constant speed. Use it for continuous things like a loading spinner.cubic-bezier(x1, y1, x2, y2)describes a custom curve. If your tool exports four numbers, copy them exactly.
If your design tool uses a named spring or a different easing system, translate it to a CSS equivalent before handoff, or say plainly that no exact CSS equivalent exists and give the closest one. Otherwise the developer will guess.
Motion tokens
Duration and easing values repeat across a product. Name them once, the same way you named colors and spacing. This keeps a spec that says "duration-fast" tied to one value in code.
{
"motion": {
"duration": {
"fast": { "value": "150ms" },
"base": { "value": "250ms" },
"slow": { "value": "400ms" }
},
"easing": {
"enter": { "value": "cubic-bezier(0, 0, 0.2, 1)" },
"exit": { "value": "cubic-bezier(0.4, 0, 1, 1)" },
"move": { "value": "cubic-bezier(0.4, 0, 0.2, 1)" }
}
}
}The same tokens become CSS custom properties:
:root {
--motion-duration-fast: 150ms;
--motion-duration-base: 250ms;
--motion-duration-slow: 400ms;
--motion-easing-enter: cubic-bezier(0, 0, 0.2, 1);
--motion-easing-exit: cubic-bezier(0.4, 0, 1, 1);
--motion-easing-move: cubic-bezier(0.4, 0, 0.2, 1);
}
.button {
transition:
background-color var(--motion-duration-fast) var(--motion-easing-enter);
}
.button:hover {
background: var(--color-brand-primary-hover);
}Now an annotation can say "background-color, duration-fast, easing-enter," and both sides know the exact values.
Animate the cheap properties
Not every property is equally cheap for the browser to animate. Changing transform and opacity is usually smooth, because the browser can often handle these without recalculating the page layout. Animating width, height, top, left, or margin forces layout work on every frame and can look choppy on slower devices.
When you design a movement, say in the spec what is moving and how it can be built:
- A panel that slides in should be described as
transform: translateX(...), not as a change inleft. - A card that grows on hover should be described as
transform: scale(...), not as a change inwidth. - A fade should be
opacity.
If your design truly needs an animated height, such as an accordion that expands, flag it. The developer can then choose a technique on purpose and test its performance.
A worked example: a dropdown menu
Here is a complete interaction annotation for a dropdown. It joins the state documentation from the previous chapter with the motion rules.
Open.
- Trigger: click or Enter/Space on the toggle button.
- Target: the menu panel.
- Start:
opacity: 0,transform: translateY(-4px). - End:
opacity: 1,transform: translateY(0). - Timing:
duration-fast,easing-enter.
Close.
- Trigger: click outside, Esc, or selecting an item.
- End:
opacity: 0. No movement. - Timing: 120 ms,
easing-exit. - Focus returns to the toggle button.
Interrupt. If the user closes the menu during the open animation, the menu reverses from its current position and does not jump to the start.
Here is one way a developer could build the open and close behavior:
.menu {
opacity: 0;
transform: translateY(-4px);
visibility: hidden;
transition:
opacity 120ms var(--motion-easing-exit),
transform 120ms var(--motion-easing-exit),
visibility 0s linear 120ms;
}
.menu[data-open="true"] {
opacity: 1;
transform: translateY(0);
visibility: visible;
transition:
opacity var(--motion-duration-fast) var(--motion-easing-enter),
transform var(--motion-duration-fast) var(--motion-easing-enter),
visibility 0s;
}The visibility rule matters. An element at opacity: 0 can still be focused and read by a screen reader. Setting visibility: hidden after the fade removes it from both. A designer does not have to write this CSS, but the annotation should say "hidden from keyboard and screen readers when closed" so the requirement exists.
The sequence of the interaction looks like this:
A diagram like this is worth including for any interaction with more than two states. It shows the interrupted paths that a pair of before and after frames can't.
Reduced motion
Some people get dizzy or distracted from large movement on screen. Operating systems let users turn on a "reduce motion" setting, and browsers expose it to CSS through the prefers-reduced-motion media query. Your handoff should state what happens in that case. Without a statement, the developer must decide alone.
A sensible default rule:
- Keep short fades and color changes. They are rarely a problem.
- Remove or replace large movement, such as sliding panels, parallax, zooming, and spinning.
- Never rely on motion alone to convey meaning. Pair it with a visible change in text, color, or icon.
@media (prefers-reduced-motion: reduce) {
.menu {
transform: none;
transition-duration: 0.01ms;
}
}Interactions that are not motion
Interaction specs also cover behavior that has no animation at all. Write these down too:
- Keyboard behavior. Which keys open, close, move between items, and select. Tab order for the component.
- Focus management. Where focus goes when a modal opens, and where it returns when it closes.
- Touch behavior. Hover does not exist on touch screens. If a hover reveals information, say what touch users see instead.
- Timing of feedback. If an action takes longer than about a second, show a loading state. The loading state belongs to the state list, but the threshold for showing it belongs here.
- Scroll behavior. Sticky headers, scroll-triggered reveals, and scroll snapping, including at which scroll position each begins.
- Gestures. Swipe, drag, and long press, with a non-gesture alternative.
Common mistakes
- Handing over only a prototype. The developer sees a result and must reverse-engineer timing from playback.
- Vague words. "Quick," "smooth," and "bouncy" mean different things to different people. Use milliseconds and named easings.
- Different values for the same kind of change. If every hover uses a different duration, the interface feels uneven. Use motion tokens.
- Animating layout properties. This causes jank and is easy to avoid by describing movement as
transform. - Forgetting interruption. Real users click again before the animation ends.
- Omitting reduced motion. It becomes the developer's guess, or is skipped.
- Describing hover only. Every hover interaction needs a keyboard focus and a touch equivalent.
Where this goes in the file
Place the motion annotations beside the component they belong to, in the same frame as the state documentation. Link to a short "Motion" page in the file that lists the motion tokens with their values and gives one example of each. This follows the file organization from earlier in the tutorial: the developer finds the rule next to the component and the shared values on one page.
Exercise
A designer annotates a slide-in side panel with the note "slides in smoothly from the left." Rewrite the annotation so a developer can build it without guessing. Include the trigger, the properties, the timing with tokens from this chapter, the exit behavior, and the reduced motion rule.
Show answer
A good answer includes: Trigger: click on the "Filters" button. Properties: transform: translateX(-100%) to translateX(0), and opacity 0 to 1. Timing: duration-base (250 ms) with easing-enter. Exit: on close button, Esc, or click on the backdrop, the panel moves back with duration-fast (150 ms) and easing-exit. Interruption: reversing from the current position if triggered mid-animation. Focus: moves into the panel on open and returns to the "Filters" button on close; the panel is hidden from keyboard and screen readers when closed. Reduced motion: no translation, only a fade of 100 ms or less. The movement is described with transform, not left, to avoid layout work.
Exercise
Your design has a card that reveals a "Quick view" link only on hover. List two things the motion and interaction spec must add so this works for keyboard and touch users.
Show answer
First, the link must also appear when the card or anything inside it receives keyboard focus (for example with :focus-within), so keyboard users can reach it. Second, touch screens have no hover, so the spec must say either that the link is always visible on touch devices or that another control, such as a tap target or an icon button, provides the same action. The spec should also confirm the link is in the tab order and that the reveal uses opacity rather than a layout change.