Ask any question about CSS here... and get an instant response.
Post this Question & Answer:
How can I use CSS to create a smooth fade-in effect on page load?
Asked on May 23, 2026
Answer
To create a smooth fade-in effect on page load using CSS, you can utilize CSS animations. This involves defining a keyframe animation that changes the opacity from 0 to 1 over a specified duration.
<!-- BEGIN COPY / PASTE -->
<style>
.fade-in {
opacity: 0;
animation: fadeIn 2s forwards;
}
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
</style>
<div class="fade-in">
This content will fade in smoothly on page load.
</div>
<!-- END COPY / PASTE -->Additional Comment:
- Apply the "fade-in" class to any element you want to animate.
- The "animation" property specifies the name of the keyframe (fadeIn), duration (2s), and ensures the animation stays at the final state with "forwards".
- You can adjust the duration to make the fade-in effect faster or slower.
- This method requires no JavaScript and is purely CSS-based.
Recommended Links:
