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 Mar 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 ease 2s;
animation-fill-mode: forwards;
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
</style>
<div class="fade-in">
This content will fade in on page load.
</div>
<!-- END COPY / PASTE -->Additional Comment:
- The "fade-in" class applies the animation to any element you want to fade in.
- The "animation-fill-mode: forwards;" ensures the element stays visible after the animation completes.
- Adjust the duration (e.g., "2s") to make the fade-in faster or slower.
- The animation will automatically trigger when the page loads.
Recommended Links:
