Skip to content

CSS Hover Effects That Work on Touch and Keyboard

What you'll learn: Learn to choose which properties to transition, why `transition: all` is a trap, and how to give keyboard users the same feedback as mouse users.

Transition only what changes

The Minimal Button in the catalog keeps its hover feedback to a single property: `transition: opacity 0.2s ease`. That is the efficient default — opacity is painted on its own layer and cannot trigger layout. When a hover state changes more than one property, list them explicitly instead of reaching for a shortcut.

The shortcut most codebases reach for is `transition: all`. The Apple and Brutalist buttons in this tutorial use it (`transition: all 0.3s ease` and `transition: all 0.1s ease`). It reads compactly, but it animates every property that changes for any reason — including ones you did not intend, such as width, height, or margin introduced by a state class. On a page with many interactive elements, that turns a hover into avoidable paint and layout work. The catalog keeps these buttons small enough that the cost is bounded; as a habit, prefer the explicit property list.

Ultra Minimal ButtonFull component →
Complete HTML + CSS
.minimal-button {
  padding: 0.75rem 1.5rem;
  background: transparent;
  border: none;
  color: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

.minimal-button:hover {
  opacity: 0.7;
}

<button class="minimal-button">Minimal →</button>

Hover is decoration; focus is navigation

Every hover style in this catalog is decorative: the button is already visible and clickable without hovering. That is the correct baseline, because a keyboard user never triggers `:hover`. When you adapt these components, mirror the hover affordance on `:focus-visible` so the state is perceivable while tabbing:

  • The catalog's own accessibility notes call this out: Minimal asks for a visible focus state, Brutalist asks to keep focus states visible, and Apple asks for a 44×44px touch target.
  • `transition: all` on a focusable element can animate the focus ring itself — another reason to name properties.
Pairing hover with keyboard focus
/* Mirror the hover feedback for keyboard users. */
.cta-button:hover,
.cta-button:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.25);
}

/* Keep a visible focus ring — do not remove the outline. */
.cta-button:focus-visible {
  outline: 2px solid #a78bfa;
  outline-offset: 3px;
}

Touch devices never hover

On phones and tablets the first tap usually triggers hover emulation before the click, which can leave the element stuck in its hover state or require a second tap. The safe rule: never gate essential content or functionality behind `:hover`. Hover may add delight — scale, glow, shadow — but the component must be complete without it.

If you do need to adjust styles for touch, CSS gives you a media query for the input capability rather than the screen size: `@media (hover: none) { ... }`. Use it to drop hover-only transforms, not to hide content.

Apple Style ButtonFull component →
Complete HTML + CSS
.apple-button {
  padding: 0.75rem 2rem;
  border-radius: 9999px;
  background: white;
  color: black;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: all 0.3s ease;
}

.apple-button:hover {
  transform: scale(1.05);
}

.apple-button:active {
  transform: scale(0.98);
}

<button class="apple-button">Learn More</button>

Fast feedback still needs restraint

The Brutalist button's `0.1s` transition is deliberately abrupt — hard shadows and offset borders look wrong when they ease slowly. Duration is part of the design language, not a constant. The practical range for UI feedback is roughly 100–300ms; anything longer than that starts to feel like latency rather than response.

Finally, respect users who ask for less motion. Hover transitions are usually mild enough to keep, but if a hover state includes a looping animation, wrap it in the same reduced-motion guard used by the animated buttons — the pattern is covered in the prefers-reduced-motion tutorial.

Brutalist ButtonFull component →
Complete HTML + CSS
.brutalist-button {
  padding: 1rem 2rem;
  background: white;
  color: black;
  font-weight: 900;
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  border: 4px solid black;
  cursor: pointer;
  box-shadow: 6px 6px 0 #000;
  transition: all 0.1s ease;
}

.brutalist-button:hover {
  transform: translate(-3px, -3px);
  box-shadow: 9px 9px 0 #000;
}

.brutalist-button:active {
  transform: translate(3px, 3px);
  box-shadow: 2px 2px 0 #000;
}

<button class="brutalist-button">BRUTALIST</button>

Where to go next