Hover and Transitions
Pseudo-classes such as :hover and :focus style an element in a given state. transition animates the change smoothly: name the property, a duration, and optionally an easing function and delay.
Always style :focus-visible too, so keyboard users can see where they are. Transition cheap properties like opacity and transform for smooth results.
Example
<style>
button {
background: #166534; color: white; border: 0;
padding: 10px 18px; border-radius: 6px;
transition: transform 0.2s ease, background 0.2s ease;
}
button:hover, button:focus-visible {
background: #15803d;
transform: translateY(-2px);
}
</style>
<button>Hover me</button>Exercise
Style the button when the mouse is over it.
button: { background: orange; }
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.