Motion and Interaction · Labs · 3 min read
Animate a button's states
A guided lab: write a state sheet for one button (rest, hover, press, focus), give each state a duration and a curve from tokens, build it in CSS, and make a reduced-motion version. About an hour, with a code editor or CodePen.
A button is the smallest motion system you'll ever build, and the one people touch most. It has to answer a hover, give under a press and show focus at once, hundreds of times a day, without ever feeling slow. You'll write its state sheet first, then build it, then take the movement away and check it still answers.
What you'll do:
- Write a state sheet for one button
- Pick a duration and a curve for each state, from tokens
- Build the states in CSS with transitions
- Make and test the reduced-motion version
You'll need: a code editor or a free CodePen, a browser, the system setting for reduced motion (see step 5), about an hour.
1. Write the state sheet
Hover it, press and hold it, then reach it with Tab.
| State | What changes | Duration | Easing | Reduced motion |
|---|---|---|---|---|
| Rest | Accent fill, label in the on-accent colour | Returns in 150 ms | standard | Same |
| Hover | Fill moves 20% toward the text colour | --motion-duration-feedback 150 ms | cubic-bezier(0.2, 0, 0, 1) | Same: a colour change is not motion |
| Press | scale(0.96), the button gives under the finger | --motion-duration-press 100 ms | cubic-bezier(0.2, 0, 0, 1) | No scale; the colour still answers |
| Focus | 2 px ring in the accent colour, 3 px away | 0 ms, instant | None | Same |
Before any code, fill in one row per state: what changes, how long, which curve, and what happens under reduced motion. The figure is a finished sheet, and the button above it runs it. Try it with a mouse, with a finger, and with the Tab key.
Use the states from Interactive states: hover, press, focus. If your button can be disabled or loading, add those rows too.
2. Choose the values from tokens
Use durations that feel instant for feedback people trigger all day. Atlassian's range for hover and press is 50 to 150 ms (Atlassian Design System, Motion). The sheet uses two tokens from Motion tokens:
- Hover:
--motion-duration-feedback, 150 ms - Press:
--motion-duration-press, 100 ms, shorter, because a press must answer the finger before it lifts
Both use the standard curve, cubic-bezier(0.2, 0, 0, 1). Focus gets no transition at all: a keyboard user needs to see where they are the moment they arrive.
3. Build it
This is the CSS the button in the figure runs, exactly:
.mo-d-kit {
--motion-duration-feedback: 150ms;
--motion-duration-press: 100ms;
--motion-easing-standard: cubic-bezier(0.2, 0, 0, 1);
}
.mo-d-btn {
appearance: none; border: 0; min-height: 44px; padding: .6rem 1.4rem; border-radius: 999px;
background-color: var(--accent-fill); color: var(--on-accent); font: 600 var(--t-small)/1.2 var(--text); cursor: pointer;
transition: background-color var(--motion-duration-feedback) var(--motion-easing-standard),
transform var(--motion-duration-feedback) var(--motion-easing-standard);
}
.mo-d-btn:hover { background-color: color-mix(in srgb, var(--accent-fill) 80%, var(--ink)); }
.mo-d-btn:active { transform: scale(0.96); transition-duration: var(--motion-duration-press); }
.mo-d-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
@media (prefers-reduced-motion: reduce) {
.mo-d-btn:active { transform: none; }
}
Three details worth copying:
- Only
background-colorandtransformtransition. Nevertransition: all: it animates things you didn't plan, like the outline. - The press shortens the duration with
transition-durationon:active. Going in takes 100 ms; coming back takes 150. :focus-visible, not:focus. The ring shows for the keyboard, not after every mouse click (MDN, :focus-visible).
Build your own version with your product's colours. Keep the structure.
4. Test the feel
- Click fast, ten times. Does it ever feel late? If so, the duration is too long.
- Press and hold. The button should stay pressed until you let go.
- Tab to it. The ring must appear at once, with enough contrast against the background (see Accessibility fundamentals).
- Try it on a phone. Touch has no hover; the press state has to carry the feedback alone.
5. Make the reduced-motion version
Switch on reduced motion in your system: on macOS 26, System Settings › Accessibility › Motion › Reduce motion; on Windows 11, Settings › Accessibility › Visual effects › Animation effects (off); on iOS, Settings › Accessibility › Motion; on Android, Settings › Accessibility › Remove animations (MDN, prefers-reduced-motion).
Press the button again. The scale is gone, the colour still changes. That's the right split: WCAG's definition of motion animation leaves out colour changes that don't change size, shape or position (W3C, Understanding 2.3.3). The button still answers, it just doesn't move.
6. Check your work
Reflection questions: Did 150 ms feel right for your hover, or did you want it shorter? What would a loading state add to the sheet?
Related
Interactive states: hover, press, focus · Motion tokens · Anatomy of a microinteraction · CSS transitions and animations · Affordances, signifiers and feedback