The whileHover and whileTap Props
What you'll learn: How to add instant visual feedback on hover and tap without writing event handlers or managing state yourself.
The Instant Feedback Pattern
Up until now, you've animated based on state changes—a component mounts, or useState triggers a value update, then Framer Motion animates to the new target. But what about common UI interactions like hovering over a button or clicking it? You could track isHovered with onMouseEnter/onMouseLeave and isPressed with onMouseDown/onMouseUp, but that's tedious boilerplate for every interactive element.
Framer Motion gives you whileHover and whileTap props that handle this automatically. They define animation targets that apply only while the interaction is happening—then smoothly reverse when it ends.
How They Work
<motion.button
whileHover={{ scale: 1.1 }}
whileTap={{ scale: 0.95 }}
>
Click Me
</motion.button>
When the user hovers, the button scales up to 1.1. When they tap (mouse down or touch), it scales down to 0.95. When they release or move away, it returns to its default state—all without you writing a single event handler or state variable.
You can combine these with other props:
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
whileHover={{ backgroundColor: "#4A90E2" }}
transition={{ duration: 0.2 }}
>
Hover for color change
</motion.div>
The transition applies to all animations, including hover/tap effects.
When to Use This
Perfect for buttons, cards, icons, and any clickable UI element where you want immediate tactile feedback. It keeps your code clean—no need for multiple state booleans cluttering your component.
Key Takeaway: whileHover and whileTap provide declarative, automatic visual feedback for mouse and touch interactions without manual state management.