Charging Animation of Battery | HTML and CSS

Hello guys in this tutorial we will create Charging Animation of Battery Using HTML and 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>Battery Animation</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<link rel="stylesheet" type="text/css" href="style.css"> 
</head>
<body>
	<div class="main-outer">
		<div class="box"></div>
	</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;
  font-family: 'Roboto', sans-serif;
} 
body {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background: #f1f2f3;
}
.box {
    width: 150px;
    height: 80px;
    border: 5px solid;
    position: relative;
}
.box:before {
    content: "";
    position: absolute;
    top: 50%;
    right: -10px;
    transform: translate(10px, -50%);
    width: 10px;
    height: 25px;
    background-color: transparent;
    border: 5px solid;
}
.box:after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 97%;
    height: 95%;
    background: #000;
    animation: animate 2.5s linear infinite;
}
@keyframes animate {
    0% {
        width: 0%;
    }
    25% {
        width: 25%;
    }
    50% {
        width: 50%;
    }
    75% {
        width: 75%;
    }
    100% {
        width: 95%;
    }
} 

Output:

Subscribe Now

Leave a Comment