Ask any question about CSS here... and get an instant response.
Post this Question & Answer:
How can I create a smooth CSS transition for changing background colors? Pending Review
Asked on Mar 27, 2026
Answer
To create a smooth CSS transition for changing background colors, you can use the `transition` property. This property allows you to define the duration and timing of the transition effect when the background color changes.
<!-- BEGIN COPY / PASTE -->
<style>
.color-transition {
background-color: lightblue;
transition: background-color 0.5s ease;
}
.color-transition:hover {
background-color: lightcoral;
}
</style>
<div class="color-transition" style="padding: 20px;">
Hover over this box to see the color transition.
</div>
<!-- END COPY / PASTE -->Additional Comment:
- The `transition` property specifies which CSS property to animate (e.g., `background-color`), the duration (e.g., `0.5s`), and the timing function (e.g., `ease`).
- The `ease` timing function creates a smooth start and end to the transition.
- You can apply transitions to multiple properties by separating them with commas.
- Hover effects are a common use case for CSS transitions, enhancing user interaction.
Recommended Links:
