Home >Web Front-end >CSS Tutorial >2020-05-28 - How to use CSS to create a fade-in effect when the page loads?
Use animation and transition properties to create fade-in effects on page loads using CSS.
Method 1: Use CSS animation properties: CSS animation is defined by 2 keyframes. One sets the opacity to 0 and the other sets the opacity to 1. When the animation type is set to easy, the animation fades in and out smoothly across the page.
This attribute applies to the body tag. Whenever the page loads, this animation will play and the page will appear to fade in. The fade-in time can be set in the animation attribute.
The code is as follows:
body {
animation: fadeInAnimation ease 3s
animation-iteration-count: 1;
animation-fill-mode: forwards;
}
@keyframes fadeInAnimation {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
Example:
}
Example: