CSS techniques

CSS button hover effects that feel good (and stay accessible)

Four CSS button hover effects to copy (shine, fill, animated border and lift), how the pseudo-element technique works, and the accessibility details most snippets miss.

Good CSS button hover effects are quick (around 0.2–0.5 seconds), animate only transform, opacity or shadows, run on keyboard focus as well as hover, and switch off for people who prefer reduced motion. Most of the effects that feel polished use a pseudo-element: a layer drawn with ::before or ::after that slides, fades or sweeps across the button.

This guide gives you four effects to copy, explains the technique behind each, and covers the accessibility details that are easy to miss.

Key takeaways

  • Animate transform and opacity for smooth effects; avoid animating width, height or padding.
  • Always pair :hover with :focus-visible, and never remove the focus outline without replacing it.
  • Wrap motion in @media (prefers-reduced-motion: reduce) so it can be switched off.
  • Keep buttons at least 24 × 24 CSS pixels to meet WCAG 2.2’s minimum target size; larger is better.
  • Hover doesn’t exist on touch screens, so the button must look clickable without the effect.

The technique behind most hover effects

A button can only have one background, but its ::before and ::after pseudo-elements give you two extra layers to animate. Position one absolutely over the button, hide it with a transform, and move it into view on hover. Three supporting lines keep it tidy:

  • position: relative on the button, so the layer is positioned against it.
  • overflow: hidden, so the layer doesn’t spill outside the rounded corners.
  • isolation: isolate, which lets a layer with z-index: -1 sit behind the label but in front of the button’s background.

Which effect suits which button?

ButtonGood fitWhy
Main call to actionShine sweep, fill slideNoticeable without moving the layout
Secondary actionsLift, underlineQuiet feedback that doesn’t compete
Dark or image backgroundsGlass, glow, animated borderStand out against busy or dark areas
Forms and dense UIsColour change onlyFast, predictable and easy to read

Use one hover style per type of button across the site. Mixing several effects on one page makes the interface feel inconsistent.

Effect 1: shine sweep

A diagonal band of light slides across the button. It works on any colour and draws the eye to a main call to action.

.btn-shine {
  position: relative;
  overflow: hidden;
}
.btn-shine::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, transparent 30%, rgba(255, 255, 255, .45) 50%, transparent 70%);
  transform: translateX(-120%);
  transition: transform 0.5s cubic-bezier(.2, .8, .2, 1);
  pointer-events: none;
}
.btn-shine:hover::before,
.btn-shine:focus-visible::before {
  transform: translateX(120%);
}

Effect 2: fill slide

A second colour fills the button from the left. Scaling a layer is smoother than animating its width.

.btn-fill {
  position: relative;
  overflow: hidden;
  isolation: isolate;
}
.btn-fill::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: #16c79a;
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.35s ease;
}
.btn-fill:hover::before,
.btn-fill:focus-visible::before {
  transform: scaleX(1);
}

Effect 3: animated gradient border

A gradient border rotates around the button. Normally gradients can’t be animated, but registering a custom property with @property lets the browser animate its angle. @property has worked in all major browsers since July 2024; older ones show a static gradient border.

@property --angle {
  syntax: "<angle>";
  initial-value: 0deg;
  inherits: false;
}
.btn-border {
  border: 2px solid transparent;
  border-radius: 12px;
  background:
    linear-gradient(#0b1020, #0b1020) padding-box,
    conic-gradient(from var(--angle), #5ce1c6, #7a5cff, #ff6fb1, #5ce1c6) border-box;
}
.btn-border:hover,
.btn-border:focus-visible {
  animation: spin-border 3s linear infinite;
}
@keyframes spin-border {
  to { --angle: 360deg; }
}

Effect 4: lift

The simplest effect, and often the best for secondary buttons: the button rises slightly and its shadow deepens.

.btn-lift {
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.btn-lift:hover,
.btn-lift:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(15, 23, 42, .25);
}
.btn-lift:active {
  transform: translateY(0);
}

Make hover effects accessible

RequirementWhyHow
Works with the keyboardKeyboard users never hoverAdd :focus-visible wherever you use :hover
Visible focusPeople need to see where they areKeep the outline, or replace it with an equally clear one
Reduced motionMovement can cause dizziness or nauseaTurn transitions and animations off in a prefers-reduced-motion query
Target sizeSmall targets are hard to hitAt least 24 × 24 CSS pixels (WCAG 2.2, SC 2.5.8, AA); aim for 44 × 44 on touch
Readable in every stateEffects can lower contrast mid-animationCheck the label on both the start and end colours
@media (prefers-reduced-motion: reduce) {
  .btn-shine::before,
  .btn-fill::before,
  .btn-lift {
    transition: none;
  }
  .btn-border:hover,
  .btn-border:focus-visible {
    animation: none;
  }
}

Tip: On phones, a tap can leave a hover style stuck on until the person taps elsewhere. Wrapping purely decorative hover styles in @media (hover: hover) applies them only on devices that can actually hover.

Common mistakes

  • Animating layout properties. Transitions on width, height, padding or margin make the browser recalculate the layout every frame. Use transforms instead.
  • Effects that are too slow. Anything over about half a second feels laggy on a control people click often.
  • Removing the focus outline with outline: none and nothing to replace it.
  • Hiding the label. Effects that slide text away or fade it out make the button harder to read just as someone is about to click.

Build your own button

The button hover effects generator has ten effects, including all four above, ready to style with your colours, radius, size and speed. Every effect includes :focus-visible and reduced-motion support, and if you use WordPress, Elementor, Divi, Bricks or Breakdance, choose it under Paste into to get code that targets your builder’s own button. There are builder walkthroughs for Divi and Elementor on the Journal. For shadow-based effects, the box shadow generator makes layered shadows that suit the lift effect.

Sources: W3C: Understanding SC 2.5.8 Target Size (Minimum), MDN: @property.