HTML+CSS: Loading Animation

loadingAnimation

index.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Interesting Loading Animation</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="loading">
<span>loading..</span>
</div>
</body>
</html>

style.css

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
*{
/* initialization, defining the margin and padding */
margin: 0;
padding: 0;
}

body{
/* 100% window height */
height: 100vh;
/* gradient background */
background: linear-gradient(to bottom, #2b6876, #09203f);
display: flex;
/* center at the main axis, which is horizontally */
justify-content: center;
/* center flex items along the cross axis of the current line of the flex container */
align-items: center;
}

.loading{
width: 200px;
height: 200px;
/* this tells the browser that the sum of padding and margin of the box is 200px */
box-sizing: border-box;
border-top: 10px solid #63a69f;
border-radius: 50%;
position: relative;
animation: a1 2s linear infinite;
}

.loading::after,.loading::before{
content: "";
width: 200px;
height: 200px;
position: absolute;
left: 0;
top: -10px;
box-sizing: border-box;
border-radius: 50%;
}

.loading::after{
border-top: 10px solid #f2e1ac;
transform: rotate(240deg);
}

.loading::before{
border-top: 10px solid #f2836f;
transform: rotate(120deg);
}

.loading span{
position: absolute;
width: 200px;
height: 200px;
line-height: 200px;
text-align: center;
color: beige;
animation: a2 2s linear infinite;
font-size: larger;
}

@keyframes a1 {
to{
transform: rotate(360deg);
}
}

@keyframes a2 {
to{
transform: rotate(-360deg);
}
}