How to use CSS animation property to create fade-in effect In CSS
To create a fade-in effect using CSS animation, define two keyframes with opacity settings (0 and 1). Apply the animation to the body tag with the ‘ease’ type for a smooth transition. This animation, triggered on page load, provides a gradual fade-in appearance. Adjust the duration using the animation property.
Syntax:
body {
animation: fadeInAnimation ease 3s;
animation-iteration-count: 1;
animation-fill-mode: forwards;
}
@keyframes fadeInAnimation {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
Example: This example shows how to create a fade-in effect on page load using CSS animation property.
<!DOCTYPE html>
<html>
<head>
<title>
To create fade-in effect
on page load using CSS
</title>
<style>
body {
animation: fadeInAnimation ease 3s;
animation-iteration-count: 1;
animation-fill-mode: forwards;
}
h1 {
color: green;
}
@keyframes fadeInAnimation {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
</style>
</head>
<body>
<h1>w3wiki</h1>
<b>
How to create fade-in effect
on page load using CSS
</b>
<p>
This page will fade in
after loading
</p>
</body>
</html>
Output:
How to create fade-in effect on page load using CSS ?
The fade-in effect is used to create an animation effect on an element in a web page. This makes our webpage more interactive and increases engagement. There are several methods to apply fade-in animation in CSS. In this guide, we will cover methods to apply the fade-in effect in CSS with examples and their explanation.
To achieve a fade-in effect on page load, set the element’s initial opacity to 0 in your CSS. Apply a transition to the opacity property with a specified duration for a smooth fade-in as the page loads. Use animation and transition property to create a fade-in effect on page load using CSS.