Course contentsShow
← Web Development
Lesson 2566 of 2,98246. Animation LibrariesFree lesson

Hover, Tap, and Focus Animations

Add interactive micro-interactions using whileHover, whileTap, and whileFocus gesture props.

Hover, Tap, and Focus Animations

You'll learn how to add smooth, responsive micro-interactions that trigger when users hover, tap, or focus on elements using Framer Motion's gesture props.

The Core Idea

Framer Motion provides three special props—whileHover, whileTap, and whileFocus—that let you define animation states triggered by user interactions. Instead of writing separate event handlers and managing state manually, you simply declare what the element should look like during these interactions, and Framer Motion handles the rest.

Think of these as "conditional styling on steroids." Just as CSS :hover changes appearance instantly, these gesture props create smooth, animated transitions to a new visual state while the interaction is active, then automatically reverse when it ends.

How They Work

Each gesture prop accepts an object describing the animated state:

<motion.button
  whileHover={{ scale: 1.1 }}
  whileTap={{ scale: 0.95 }}
  whileFocus={{ boxShadow: "0px 0px 8px rgb(59, 130, 246)" }}
>
  Click Me
</motion.button>
  • whileHover: Activates when the mouse pointer enters the element
  • whileTap: Activates during a mouse click or touch press
  • whileFocus: Activates when the element receives keyboard focus (important for accessibility)

These work seamlessly together. A button can scale up on hover, compress slightly when tapped, and show a focus ring when accessed via keyboard—all with just three props.

The animations automatically respect your transition configuration from the transition prop, maintaining consistency across your interface.

Key Takeaway: Use whileHover, whileTap, and whileFocus to create delightful, responsive micro-interactions that feel natural and polished without manual event management.