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 a background image on page load using CSS?
Asked on Apr 18, 2026
Answer
To create a smooth fade-in effect for a background image on page load using CSS, you can use CSS animations to gradually change the opacity of an element. Here's a simple example to demonstrate this effect.
<!-- BEGIN COPY / PASTE -->
<style>
.fade-in-bg {
background-image: url('your-image.jpg');
background-size: cover;
background-position: center;
height: 100vh;
opacity: 0;
animation: fadeIn 2s forwards;
}
@keyframes fadeIn {
to {
opacity: 1;
}
}
</style>
<div class="fade-in-bg"></div>
<!-- END COPY / PASTE -->Additional Comment:
- Ensure the image URL in the background-image property is correct.
- The animation duration (2s) can be adjusted to make the fade-in slower or faster.
- The forwards value in the animation property keeps the final state of the animation.
- This example assumes the background image covers the entire viewport height (100vh).
Recommended Links:
