Space Travel Animation using HTML and CSS

Priyanka Das
2 min readMay 13, 2021

HTML CODE

<!DOCTYPE html>
<html>
<head><title>space</title>
<meta charset=”utf-8">
<link href=”star.css” rel=”stylesheet”>
</head>
<body>
<h1>SPACE TRAVEL</h1>
<div id=”space”>
<div class=”stars”></div>
<div class=”stars”></div>
<div class=”stars”></div>
<div class=”stars”></div>
</div>
</body>
</html>

CSS CODE

body{
background: #000;
font-family: ‘Orbitron’, sans-serif;
}
h1 {
position: absolute;
z-index: 1;
top: 50%;
left: 50%;
margin: -1.5em -2.5em;
width: 5em;
color: white;
font-size: 5em;
text-align: center;
text-shadow: 0 0 3px #6cf;
}
#space, .stars {
overflow: hidden;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.stars {
background-image:
radial-gradient(2px 2px at 20px 30px, #eee, rgba(0,0,0,0)),
radial-gradient(2px 2px at 40px 70px, #fff, rgba(0,0,0,0)),
radial-gradient(2px 2px at 50px 160px, #ddd, rgba(0,0,0,0)),
radial-gradient(2px 2px at 90px 40px, #fff, rgba(0,0,0,0)),
radial-gradient(2px 2px at 130px 80px, #fff, rgba(0,0,0,0)),
radial-gradient(2px 2px at 160px 120px, #ddd, rgba(0,0,0,0));
background-repeat: repeat;
background-size: 200px 200px;
animation: zoom 5s infinite;
opacity: 0;
}

.stars:nth-child(1) {
background-position: 50% 50%;
animation-delay: 0s;
}
.stars:nth-child(2) {
background-position: 20% 60%;
animation-delay: 1s;
}
.stars:nth-child(3) {
background-position: -20% -30%;
animation-delay: 2s;
}
.stars:nth-child(4) {
background-position: 40% -80%;
animation-delay: 3s;
}
@keyframes zoom {
0% {
opacity: 0;
transform: scale(0.5);
animation-timing-function: ease-in;
}
85% {
opacity: 1;
transform: scale(2.8);
animation-timing-function: linear;
}
100% {
opacity: 0;
transform: scale(3.5);
}
}

For more stories follow Priyanka Das

Also follow us on Instagram Skill Self

--

--

Priyanka Das

Instructor at Udemy. 6+ years of experience in Web Development. Machine Learning Enthusiast.