Marcus Andrey Study
Ler em português Library

Motion and Interaction · Step 3 · 7 min read

Interactive states: hover, press, focus

Every control answers before it acts: hover says "you can press me", press says "I felt that", focus says "you are here". What each state is for, how fast it should appear, how Material builds them all from one layer, and why the focus ring is the one you can never drop.

A control should answer you before it does anything. You point, it lights up. You press, it gives a little. You arrive with the keyboard, it shows a ring. Those three answers are the smallest microinteractions in any product, and they happen thousands of times a day. Get them right once, in the component, and every screen gets them for free.

What you'll be able to do after reading:

  • Say what hover, press and focus each tell a person
  • Choose how fast each one should appear, and why press is the fastest
  • Build all three from one state layer, the way Material does
  • Design a focus indicator that meets WCAG 2.2

1. One button, five states

  • RestNo layer
  • HoverLayer at 8%: "you can press me"
  • Focus (keyboard)A 3 px ring outside, layer at 12%
  • PressedLayer at 12%, at once, and a 3% squeeze
  • DisabledGrey, no layer, no pointer
One button, five states. Above, each state held still; below, the real button. Hover, focus and press all use one see-through layer of the label's colour over the fill, at Material's opacities. Hover only appears on devices that can hover, and the keyboard ring only appears for the keyboard.Live CSS: :hover inside @media (hover: hover), :focus-visible, :active. Opacities from Material Web's state tokens. Demo: Marcus Andrey, CC BY 4.0.

Try the real button with a mouse, then with your finger, then with Tab. You'll see that the states don't all appear everywhere, and that's on purpose.

State What it tells the person When it appears
Hover "This can be pressed" A mouse or trackpad pointer is over it. Touch screens have no hover
Focus "You are here" The keyboard (or a switch device) moved to it
Pressed "I felt that" Between pressing down and letting go
Disabled "Not now" The action isn't available. It should also say why, nearby

2. One layer for every state

Material Design builds hover, focus, press and drag from the same idea: a state layer, a see-through layer in the colour of the label, placed over the control. Only its opacity changes. In Material's web components the tokens are 8% for hover, 12% for focus, 12% for pressed and 16% for dragged (Material Web, state tokens; Material Design 3, States).

One layer has two big advantages. It works on any fill colour, light or dark, because it uses the label's own colour. And states can stack (hovered and focused at once) without anyone designing every combination by hand.

These are the state rules that run in the figure, exactly (the colours, padding and the disabled style live in separate rules):

.mo-b-btn {
  position: relative; isolation: isolate; overflow: hidden;
  transition: transform 100ms cubic-bezier(0.2, 0, 0, 1);
}
.mo-b-btn::before { content: ""; position: absolute; inset: 0; z-index: -1; background: currentColor; opacity: 0; transition: opacity 100ms linear; }
@media (hover: hover) { .mo-b-btn:hover::before { opacity: .08; } }
.mo-b-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.mo-b-btn:focus-visible::before { opacity: .12; }
.mo-b-btn:active { transform: scale(.97); }
.mo-b-btn:active::before { opacity: .12; transition-duration: 0ms; }
@media (prefers-reduced-motion: reduce) {
  .mo-b-btn, .mo-b-btn:active { transform: none; }   /* no squeeze; the state layer still says "pressed" */
}

3. Timing: press is instant, the rest is quick

  • Pressed: no delay at all. The press layer has transition-duration: 0ms. For an action to feel like the cause of a change, the answer has to start within 0.1 seconds (NN/g, Response Times: The 3 Important Limits). Anything slower and people press again.
  • Hover and focus: about 100 ms. Fast enough to feel immediate, slow enough not to flicker when the pointer crosses a toolbar. 100 ms is Material's short2 duration token (Material Web, motion tokens).
  • Leaving a state can be a touch slower than entering it. A layer that fades out over 100 ms after you let go reads as "done", not as a glitch.

The 3% squeeze on press is optional "give", like a real key. It's motion, so it goes under reduced motion; the layer still says "pressed" without it.


4. Hover: only where it exists

Touch screens have no hover. If a phone fakes one, the first tap often triggers the hover style and the second tap the action, or the hover sticks after you lift your finger. The @media (hover: hover) query tests whether the main pointer can hover (MDN, hover media feature), so hover styles only apply where they make sense.

The rule that follows: never put information only in hover. A tooltip that explains a button, or actions that appear only on hover, are invisible on touch and for many keyboard users. Hover can hint; it can't be the only way.


5. Focus: the state you can never drop

For people who use a keyboard, a switch device or voice control, the focus indicator is the cursor. Without it, they can't use the page at all. That's why WCAG has three criteria about it:

  • 2.4.7 Focus Visible (AA): any keyboard-operable interface has a mode where the focus indicator is visible (W3C, Understanding 2.4.7).
  • 2.4.11 Focus Not Obscured, Minimum (AA, new in 2.2): the focused item is not entirely hidden by things like sticky headers or cookie banners (W3C, Understanding 2.4.11).
  • 2.4.13 Focus Appearance (AAA): the indicator is at least as large as a 2 CSS pixel thick perimeter of the control, with at least 3:1 contrast between the focused and unfocused pixels (W3C, Understanding 2.4.13).

The figure's 3 px outline with a 3 px gap meets the AAA one too. Use :focus-visible, not :focus: browsers apply it when they judge the focus should be evident, which in practice means the keyboard ring shows and a mouse click on a button doesn't leave one behind (MDN, :focus-visible). That one selector ended the old habit of outline: none, which removed the cursor for everyone to hide it from mouse users.

Should focus animate? A ring that appears in 100 ms is fine. A ring that slides from the last control to the next one is pretty, but under reduced motion it must simply appear.


6. Disabled: grey is not an explanation

A disabled control has no hover, press or focus layer, and WCAG doesn't require text contrast for inactive components (W3C, Understanding 1.4.3). That doesn't make it good. A greyed-out "Pay" button tells people "no" without telling them why. Often it's better to keep the button active and, when pressed, show what's missing. If you do disable it, put the reason next to it.


7. Common mistakes

  • outline: none with nothing in its place.
  • A focus ring with too little contrast against the page, or hidden under a sticky header.
  • Information or actions that only appear on hover.
  • A delay or slow fade on press, so people press twice.
  • A different hover effect on every component: grow, shadow, colour, underline. Pick one system.

8. Vocabulary

Term Meaning
Hover A pointer is over the control, without pressing
Pressed (active) Between pressing down and letting go; :active in CSS
Focus The control that keyboard input goes to
:focus-visible Focus that the browser judges should be shown, usually from the keyboard
State layer A see-through layer of the label's colour whose opacity shows the state
Focus indicator What shows focus: an outline, a ring, an underline

9. Try it (no tools needed)

  1. Open a product you work on. Put the mouse away.
  2. Press Tab ten times. Can you always see where you are?
  3. Now use it on a phone. Is anything only reachable by hover?

Reflection questions: Which state did your team design last, or not at all? Where would the focus ring disappear behind a sticky header?


10. If you already practise

  • Define the states once, as tokens (layer opacities, ring width, offset, colour), and build every component from them.
  • Add "Tab through the page" to your definition of done, at 200% zoom too.
  • Check that the focus ring meets 3:1 on every background it can sit on, including dark mode and coloured sections.

Checklist

Learn more

Books, courses and videos to go deeper

Book links go to Amazon. As an Amazon Associate I earn from qualifying purchases, at no extra cost to you.

Anatomy of a microinteraction · Accessibility fundamentals · Affordances, signifiers and feedback · Animate a button's states · CSS transitions and animations

Saved only on this device.

↑ ↓ to move · Enter to open · Esc to close