Ask any question about CSS here... and get an instant response.
Post this Question & Answer:
How can I create a smooth fade-in effect for images using CSS?
Asked on Feb 28, 2026
Answer
To create a smooth fade-in effect for images using CSS, you can utilize the `opacity` property along with CSS transitions. This allows the image to gradually appear on the page.
<!-- BEGIN COPY / PASTE -->
<style>
.fade-in-image {
opacity: 0;
transition: opacity 2s ease-in-out;
}
.fade-in-image.visible {
opacity: 1;
}
</style>
<img src="your-image.jpg" alt="Description" class="fade-in-image" id="image">
<script>
window.onload = function() {
document.getElementById('image').classList.add('visible');
};
</script>
<!-- END COPY / PASTE -->Additional Comment:
- The `.fade-in-image` class sets the initial opacity to 0, making the image invisible.
- The `transition` property specifies the duration and timing function for the opacity change.
- JavaScript is used to add the `visible` class after the page loads, triggering the fade-in effect.
- Adjust the transition duration (`2s` in this example) to make the fade-in faster or slower.
Recommended Links:
