Codeloft
0 0 XP

Hover effects and transitions

6 min 20 XP + 10 for no hints

Pages feel alive when they respond to the pointer. The :hover pseudo-class applies styles while the mouse is over an element: .btn:hover { background: navy; }.

On its own, the change is instant. transition animates it: transition: background 0.3s; fades the background over 0.3 seconds.

Put the transition on the normal rule, not the hover rule, so the change animates both in and out.

Example
<style>
  .btn { background: teal; color: white; padding: 10px 18px; border: 0; border-radius: 8px; transition: transform 0.2s; }
  .btn:hover { transform: scale(1.1); }
</style>
<button class="btn">Hover me</button>
Hover doesn't exist on touch screens, so never hide important information behind it.

Your tasks

0 of 3 done
  1. Add a .btn:hover rule
  2. Change the background color on hover
  3. Add a transition to .btn so the change animates

Quick check

Where should the transition property usually go?

button.htmlUpdates as you type