← CSS tutorial

CSS

Transitions & Hover Effects

transition tells the browser to animate a property change smoothly instead of jumping to the new value instantly. On its own it does nothing visible, it needs something that actually changes a property to animate, which is exactly what :hover provides.

Example: a button that responds to hovering

button {
  background: #2f7dff;
  transform: translateY(0);
  transition: background 0.3s ease, transform 0.3s ease;
}
button:hover {
  background: #1f5fe0;
  transform: translateY(-3px);
}

:hover is a pseudo-class, a selector matching an element only while a specific condition is true (here, the mouse is over it). The moment the mouse enters, the button's background and vertical position both change; because transition is set on the base button rule (not just the hover rule), the browser smoothly animates both changes over 0.3 seconds instead of snapping instantly, and smoothly reverses the same animation on mouse-out.

This is one of the cheapest ways to make an interface feel polished and responsive, a plain instant color swap on hover works, but a short, smooth transition is what actually reads as "considered" rather than "functional."

Try it yourself
Ready to go further?

These free tutorials are a preview, our Frontend Development cohort covers it in depth, with a real project and a cohort alongside you. Closes Nov 30

Enroll in Frontend Development

Cookie preferences

Choose what you're comfortable with. You can change this any time from the footer.

Don't miss out

Ready to build something real?

Create a free account to enroll in a track, and get notified the moment a cohort opens.

Create free account