You are currently viewing The Power of CSS3 Animation: Creating a Flying Plane with Parallax Effect

CSS3 has transformed the way we create engaging web experiences. No JavaScript required—just pure CSS animations! In this tutorial, we’ll build a fun demo of a plane flying through the sky with layered background movement to showcase how different speeds and transparency can create depth and realism.


1. HTML Structure

We’ll structure the demo with a container and a few layers:

  • Sky (background color + gradient)
  • Clouds (two layers with different speeds, semi-transparent PNGs)
  • Plane (a centered image that moves slightly for effect)
  • Ground / mountains (slowest layer for parallax depth)
HTML
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CSS3 Flying Plane Animation</title>
  <link rel="stylesheet" href="styles.css">
</head>
<body>
  <div class="scene">
    <div class="sky"></div>
    <div class="clouds layer1"></div>
    <div class="clouds layer2"></div>
    <div class="plane"></div>
    <div class="mountains"></div>
  </div>
</body>
</html>

2. CSS Styling and Animation

Here’s where CSS3 works its magic.

CSS
/* General scene */
body, html {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
}

.scene {
  position: relative;
  width: 100%;
  height: 100vh;
  background: linear-gradient(to top, #87CEEB 0%, #f0f9ff 100%);
  overflow: hidden;
}

/* Sky (static gradient) */
.sky {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
}

/* Clouds (two layers for depth) */
.clouds {
  position: absolute;
  top: 50px;
  width: 200%;
  height: 200px;
  background: url('clouds.png') repeat-x;
  opacity: 0.7;
  animation: moveClouds 60s linear infinite;
}

.layer1 {
  top: 80px;
  animation-duration: 60s;
}

.layer2 {
  top: 150px;
  opacity: 0.5;
  animation-duration: 120s;
}

@keyframes moveClouds {
  from { transform: translateX(0); }
  to   { transform: translateX(-50%); }
}

/* Plane */
.plane {
  position: absolute;
  width: 150px;
  height: 80px;
  top: 40%;
  left: 40%;
  background: url('plane.png') no-repeat center/contain;
  animation: planeFloat 3s ease-in-out infinite;
}

@keyframes planeFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

/* Mountains / ground */
.mountains {
  position: absolute;
  bottom: 0;
  width: 200%;
  height: 200px;
  background: url('mountains.png') repeat-x;
  background-size: contain;
  animation: moveMountains 180s linear infinite;
}

@keyframes moveMountains {
  from { transform: translateX(0); }
  to   { transform: translateX(-50%); }
}

3. How It Works

  • Clouds: Two separate cloud layers move at different speeds (60s and 120s) to simulate parallax depth.
  • Plane: A fixed image that gently floats up and down with the planeFloat animation.
  • Mountains: The slowest moving element, reinforcing the depth of the scene.
  • Transparency: Clouds use opacity to allow the sky to show through, making the effect more natural.

4. Result

When you open this in a browser with clouds.pngplane.png, and mountains.png (transparent PNGs), you’ll see:

  • A plane gently flying across the screen,
  • Clouds drifting at different speeds,
  • Mountains moving slowly below.

All done purely with CSS3 animations — no JavaScript required!


5. Extensions

  • Add a sun layer rotating slowly.
  • Add birds with a faster animation.
  • Use multiple planes for a fleet effect.
Please follow and like us:

Leave a Reply