Ask any question about CSS here... and get an instant response.
Post this Question & Answer:
How can I use CSS to create a smooth transition effect when hovering over buttons?
Asked on Mar 15, 2026
Answer
To create a smooth transition effect on buttons when hovering, you can use the CSS `transition` property. This property allows you to define the duration and timing of changes to CSS properties, such as `background-color` or `transform`.
<!-- BEGIN COPY / PASTE -->
<style>
.button {
background-color: #4CAF50;
color: white;
padding: 10px 20px;
border: none;
cursor: pointer;
transition: background-color 0.3s ease, transform 0.3s ease;
}
.button:hover {
background-color: #45a049;
transform: scale(1.1);
}
</style>
<button class="button">Hover Me</button>
<!-- END COPY / PASTE -->Additional Comment:
- The `transition` property specifies which properties to animate and the duration of the animation.
- The `ease` timing function creates a smooth transition effect.
- In the example, both `background-color` and `transform` are animated over 0.3 seconds.
- Using `transform: scale(1.1)` enlarges the button slightly on hover.
- Ensure the button has a `cursor: pointer` for better UX.
Recommended Links:
