hover and transition: a button that reacts
Section 5: Pro CSS: shadows and movementLesson 5.2 · ⏱ 9 min
:hover means “when the mouse is over the element”. We write a new look for the button in this case. And transition makes the change happen slowly and smoothly instead of jumping all at once.
HTML
<button class="btn">▶ Play</button>
CSS
body { font-family: Tahoma, sans-serif; text-align: center; padding-top: 40px; }
.btn {
font-size: 22px;
padding: 12px 32px;
border: none;
border-radius: 999px;
color: white;
background: #2557c9;
cursor: pointer;
transition: transform 0.2s, background 0.2s;
}
.btn:hover {
background: #ff7a00;
transform: scale(1.2);
}
🖥️ The page in Robo Web:

🖥️ What happens on the stage?
In the picture the mouse is over the button: it became orange and 20% bigger (
scale(1.2)).📌 Another example: a card that rises
When the mouse goes over it, the card rises and its shadow grows smoothly.
HTML
<div class="card">🚀 My project</div>
CSS
body { font-family: Tahoma, sans-serif; padding: 40px; }
.card {
width: 200px;
padding: 24px;
font-size: 22px;
border-radius: 16px;
background: white;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
transition: transform 0.3s, box-shadow 0.3s;
}
.card:hover {
transform: translateY(-10px);
box-shadow: 0 16px 30px rgba(0, 0, 0, 0.25);
}
🖥️ The page in Robo Web:

✍️ Practise
Try the example here: copy the code into its tabs, change it, and watch the page change.
✍️ Practise here in the lesson✖ Close the labor open the lab in a new page ↗
Test yourself
- Make the button turn a little when the mouse is over it:
transform: rotate(-5deg) scale(1.1).
🎯 Challenge yourself
Easy
A link that turns red when the mouse goes over it.
👀 Show the solution🙈 Hide the solution
HTML
<a href="#" class="link">Hover over me</a>
CSS
body { font-size: 24px; padding: 30px; }
.link { color: blue; }
.link:hover { color: red; }
🖥️ The page in Robo Web:

Result: red.
Medium
A picture that grows 1.3 times smoothly.
👀 Show the solution🙈 Hide the solution
HTML
<div class="pic">🐢</div>
CSS
body { padding: 40px; }
.pic {
font-size: 70px;
width: 90px;
transition: transform 0.4s;
}
.pic:hover { transform: scale(1.3); }
🖥️ The page in Robo Web:

Result: the turtle grew.
Hard
A button that turns 10 degrees and changes colour.
👀 Show the solution🙈 Hide the solution
HTML
<button class="b">🎁 Open</button>
CSS
body { padding: 40px; }
.b {
font-size: 22px;
padding: 12px 30px;
border: none;
border-radius: 12px;
background: #5B3DF5;
color: white;
transition: all 0.3s;
}
.b:hover {
transform: rotate(10deg);
background: #E5484D;
}
🖥️ The page in Robo Web:

Result: tilted and red.

