Interaction states
5 minA Pay button that only has a default look is half designed. Build one here with hover, focus, pressed, disabled, loading and error, and watch the checklist tick as each state works.
Lesson video
Tastebud · 4:40 · Captions on screen
Draw and build every control in six states: hover, focus, pressed, disabled, loading and error.
- Why. Each state answers a question the person has right then: can I press this, is it working, did it fail? With no answer, people tap again or leave.
- Real example. Set submit_type to donate and Stripe Checkout's button reads Donate, followed by the amount. Stripe's duplicate_transaction decline code covers the same amount and card submitted very recently. (Stripe Checkout, Nov 2026)
- When to break it. A control that can't wait or fail, like a tab or checkbox, can skip loading and error. Drop a state only when you can say why it never happens.
- Common mistake. Removing the focus ring with outline: none because it looked untidy. The button still works with a mouse but shows nothing to anyone pressing Tab.
Our take. Design the loading and error states before the default one. Nobody gets stuck on a default button; they get stuck when a payment hangs or fails and the button gives no answer.
- Hover, focus and pressed: the build guesses
- Loading: nothing, so people press Pay again
- Error: nothing, so after a decline the button looks the same as before
- Hover: a darker fill under the mouse pointer
- Focus: a 3px ring outside the button for Tab
- Pressed: nudged down 1px while held
- Disabled: grey, and it says why when pressed
- Loading: Processing…, and a second press does nothing
- Error: a message under the button that names the fix
Our build of a Pay button like Stripe Checkout's, Nov 2026. Each look answers what the person needs to know at that moment.
Hover is for a mouse, focus is for the keyboard
Phones have no pointer resting on a button, so hover can't carry meaning. Focus is the state people moving with Tab depend on: draw a visible ring with :focus-visible, at 3:1 contrast or better against its background.
- A mouse or trackpad pointer rests on it
- A keyboard never triggers it, and phones have no resting pointer
- A nice extra, never the only cue
- Someone reached it with Tab or the arrow keys
- Required: WCAG 2.2, 2.4.7 Focus Visible, Level AA
- A ring at 3:1 contrast, drawn outside the button
Style both, and test the second one with the keyboard every time.
Loading stops the second payment
When Pay takes a second or two, change its label to say what's happening, and ignore further presses until the answer comes back. A button that looks idle gets pressed again.
A loading state turns a nervous second press into nothing
- Press Pay US$20.00. The request starts. The person sees nothing happening unless the button tells them.
- Label becomes Processing…. The same button now says what's going on. A Checkout button reading Checking out… is the same move.
- Second press does nothing. The click handler returns early while data-state is loading, so no duplicate payment goes out.
- Paid, or a clear error. The label comes back with the answer: a receipt, or a message that names the fix.
An error names the problem next to the button
Put the message right under the button, link it with aria-describedby, and say what to do next. Colour alone tells nobody what failed, and a toast that fades in three seconds is gone before some people finish reading.
- Red for two seconds, then blue again: nothing says what failed
- A screen reader announces nothing at all
- A toast at the top, 'Something went wrong', gone in three seconds
- Under the button: 'Your card was declined. Try another card.'
- Linked to Pay with aria-describedby
- role="alert", so screen readers read it out
Try it
Give the Pay button all six states
Disabled and error already work: press Pay before and after ticking the box. Add hover, focus, pressed and a loading look until all four checks tick.
Tab adds two spaces. Press Esc, then Tab, to leave the editor.
- Hover: a darker fill for the mouse (not yet)
- Focus: a visible ring with :focus-visible (not yet)
- Pressed: something changes on :active (not yet)
- Loading: a look for data-state="loading" (not yet)
What to notice: Press Tab until Pay has focus. Someone removed the ring with outline: none, so nothing shows where you are. Add #pay:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; } and tab again. Then try #pay:hover:not([aria-disabled="true"]) with var(--brand-hover), a 1px nudge on :active, and cursor: progress for [data-state="loading"]. Tick the box, press Pay twice quickly, and the second press changes nothing.
Quick check
In code review, a developer removes the focus ring because it 'looks ugly when you click'. What's the better fix?
Watch next
Watch it for How :focus-visible differs from :focus, and why it lets you keep a strong ring for the keyboard without showing it on every click.
Watch it for Everything a real button element gives you for free, such as focus and keyboard activation, that a clickable div makes you rebuild.
Connects to: 4.3 Fetching data from APIs · 8.2 Keyboard and focus · 13.2 Writing a spec for AI · 19.2 Component and visual tests
Sources · checked Nov 2026
- Stripe Docs: Extend Checkout with custom components (Customise the Submit button)submit_type sets the text on Checkout's submit button; the docs' US$5 donation example reads Donate US$5.00 (Donate 5.00 USD on the US English page); Checkout can require a terms of service tickbox before paying
- Stripe API: Create a Checkout Session (submit_type)submit_type values auto, book, donate, pay and subscribe; donate: 'Submit button includes a Donate label'
- Stripe Docs: Decline codesduplicate_transaction: 'A transaction with identical amount and card information was submitted very recently.' Next step: check to see if a recent payment already exists
- Apple Human Interface Guidelines: ButtonsAlways include a press state for a custom button; show an activity indicator in a button for actions that don't complete instantly, with a label such as Checkout changing to Checking out…; a 44x44 pt hit region
- W3C: WCAG 2.2 (2.4.7 Focus Visible, 1.4.11 Non-text Contrast)A visible keyboard focus indicator is required at Level AA, and visual information that identifies a component's state needs 3:1 contrast
- MDN: aria-disabledaria-disabled exposes a control as disabled without removing it from the focus order, and the script must block its action
- MDN: ARIA alert rolerole="alert" is for important, time-sensitive information and is announced when its content updates
- MDN: aria-describedbyaria-describedby points a control at the element that describes it, here the error message
- Web Platform Status: :focus-visible:focus-visible is Baseline widely available
- Web Platform Status: User action pseudo-classes:hover and :active are Baseline widely available