Hello guys today we will learn How to make animated background using HTML & CSS
First we need to create two files index.html and style.css then we need to do code for it.
Step:1
Add below code inside index.html
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Animated background</title> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <div class="animatedbg-outer"> <ul class="bg-animated"> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> </ul> </div> </body> </html>
Step:2
Then we need to add code for style.css which code i provide in below screen.
* { padding: 0; margin: 0; } body { background: #66a5ff; animation: bganimation 10s ease-in-out forwards; } @keyframes bganimation { 0% { background: #c2d9fb; } 15% { background: #a3c8ff; } 50% { background: #89b7fb; } 75% { background: #77acfb; } 100% { background: #c2d9fb; } } @-webkit-keyframes bganimation { 0% { background: #c2d9fb; } 15% { background: #a3c8ff; } 50% { background: #89b7fb; } 75% { background: #77acfb; } 100% { background: #c2d9fb; } } .animatedbg-outer { position: fixed; top: 0; left: 0; width: 100%; height: 100%; overflow: hidden; z-index: -1; } .bg-animated { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 1; } .bg-animated li { position: absolute; list-style: none; display: block; width: 40px; height: 40px; background: #303030; bottom: 50px; animation: square 25s infinite; -webkit-animation: square 25s infinite; transition-timing-function: linear; -webkit-transition-timing-function: linear; opacity: 0; } .bg-animated li:nth-child(1) { left: 4%; border-radius: 50%; background: transparent; border: 4px solid #303030; } .bg-animated li:nth-child(2) { left: 8%; width: 75px; height: 75px; -webkit-animation-delay: 2s; animation-delay: 2s; -webkit-animation-duration: 15s; animation-duration: 15s; } .bg-animated li:nth-child(3) { left: 20%; width: 175px; height: 175px; -webkit-animation-delay: 4s; animation-delay: 4s; } .bg-animated li:nth-child(4) { left: 45%; width: 90px; height: 90px; -webkit-animation-duration: 20s; animation-duration: 20s; } .bg-animated li:nth-child(5) { left: 75%; background: transparent; border:4px solid #303030; } .bg-animated li:nth-child(6) { left: 90%; width: 90px; height: 90px; -webkit-animation-delay: 3s; animation-delay: 3s; border-radius: 50%; background: transparent; border: 4px solid #303030; } .bg-animated li:nth-child(7) { left: 35%; width: 60px; height: 60px; -webkit-animation-delay: 7s; animation-delay: 7s; background: transparent; border: 4px solid #303030; } .bg-animated li:nth-child(8) { left: 60%; width: 50px; height: 50px; -webkit-animation-delay: 15s; animation-delay: 15s; -webkit-animation-duration: 40s; animation-duration: 40s; } .bg-animated li:nth-child(9) { left: 35%; width: 140px; height: 140px; -webkit-animation-delay: 2s; animation-delay: 2s; -webkit-animation-duration: 40s; animation-duration: 40s; border-radius: 50%; background: transparent; border: 4px solid #303030; } .bg-animated li:nth-child(10) { left: 95%; width: 60px; height: 60px; -webkit-animation-delay: 10s; animation-delay: 10s; } .bg-animated li:nth-child(11) { left: 15%; width: 40px; height: 40px; -webkit-animation-delay: 13s; animation-delay: 13s; border-radius: 50%; } .bg-animated li:nth-child(12) { left: 65%; width: 175px; height: 175px; -webkit-animation-delay: 7s; animation-delay: 7s; background: transparent; border: 4px solid #303030; } .bg-animated li:nth-child(13) { left: 70%; width: 100px; height: 100px; -webkit-animation-delay: 8s; animation-delay: 8s; border-radius: 50%; } .bg-animated li:nth-child(14) { left: 70%; width: 100px; height: 100px; -webkit-animation-delay: 8s; animation-delay: 8s; border-radius: 50%; } @keyframes square { 0% { -webkit-transform: translateY(0); transform: translateY(0); opacity: 0; } 50% { opacity: 1; } 100% { -webkit-transform: translateY(-700px) rotate(600deg); transform: translateY(-700px) rotate(600deg); opacity: 0; } } @-webkit-keyframes square { 0% { -webkit-transform: translateY(0); transform: translateY(0); opacity: 0; } 50% { opacity: 1; } 100% { -webkit-transform: translateY(-700px) rotate(600deg); transform: translateY(-700px) rotate(600deg); opacity: 0; } }