Ad space (banner)
🎨HTML & CSS Lessons
Lesson 20 / 50

CSS Transitions (Smooth Hover Changes)

In this lesson you'll learn how to stage smooth changes using CSS transitions, so you can build an interface that feels polished. This is for people searching "CSS transition usage."

Specifying transition makes a change in color or size animate smoothly, instead of switching "instantly." Pairing it with a change on mouse hover (:hover) is a classic combination.

The sample code specifies transition: background 0.3s, transform 0.3s; on .btn, so that hovering the mouse causes both a background-color change and an enlargement (transform: scale(1.1)) to happen smoothly. Notice that you can specify multiple properties at once, comma-separated.

A common beginner stumbling block is where to put the transition. It needs to be written on the normal state (.btn) side, not the :hover side. This is an important point also touched on in the pseudo-class lesson — getting it backwards means it won't behave the way you expect.

Adding just a short one-liner, transition: property seconds;, can make the impression of an entire site surprisingly smoother and more polished. This is one of those techniques worth remembering for easily raising the perceived quality of your visual design.

HTML & CSS
OUTPUT

💡 The preview runs entirely on this page — nothing is sent externally.

Ad space (banner)
Ad space (in-article)