How to Make a Simple Animation With HTML (Beginner‑Friendly Tutorial)

by ArihantNag in Design > Software

21 Views, 1 Favorites, 0 Comments

How to Make a Simple Animation With HTML (Beginner‑Friendly Tutorial)

04b1efa5-9f95-4df9-bb1d-6c1d401878b4.png

In this tutorial, you’ll learn how to create a simple animation using HTML, CSS, and a tiny bit of JavaScript. We’ll make a bouncing ball — perfect for beginners and great for learning how web animations work.

Supplies

You only need:

  1. A computer
  2. A browser (Chrome, Edge, etc.)
  3. A text editor (Notepad, VS Code, or anything you like)
  4. I suggest RealtimeHTML if you don't have software or just don't want to download anything (Online HTML Editor & Renderer - Real-time Live Preview | Free HTML Tester)

Create Your Project Folder

If you want to use a web-based editor, skip to step 2

Make a new folder on your computer and name it something like:

html-animation

Inside it, create a new file called:

index.html

Add the Basic HTML Structure

Capture.JPG

Open index.html or your web-based text editor and paste this:

<!DOCTYPE html>
<html>
<head>
<title>Bouncing Ball Animation</title>
<style>
body {
background: #f0f0f0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}

#ball {
width: 50px;
height: 50px;
background: red;
border-radius: 50%;
position: relative;
animation: bounce 1s infinite alternate ease-in-out;
}

@keyframes bounce {
from {
top: 0px;
}
to {
top: 200px;
}
}
</style>
</head>
<body>
<div id="ball"></div>
</body>
</html>

Understand How the Animation Works in Full Depth

1. HTML Structure


<!DOCTYPE html>

Tells the browser this is an HTML5 document.


<html>

The root element of the webpage. Everything goes inside it.


<head>

Contains information about the page that isn't directly shown on the screen.


<title>Bouncing Ball Animation</title>

Sets the text shown in the browser tab.

Example:

Bouncing Ball Animation

2. CSS Styling


<style>

Everything inside this tag is CSS (Cascading Style Sheets), which controls appearance.

Body Styling


body {

Targets the entire webpage.


background: #f0f0f0;

Sets the page background color.

#f0f0f0 is a light gray.


display: flex;

Turns the body into a Flexbox container.

Flexbox helps position elements easily.


justify-content: center;

Centers items horizontally.

Without it:

[ball]

With it:

[ball]


align-items: center;

Centers items vertically.


height: 100vh;

Makes the body height equal to 100% of the browser window.

  1. vh = Viewport Height
  2. 100vh = Full screen height

margin: 0;

Removes the browser's default margins around the page.

Without it, browsers leave small white borders.


}

Ends the body styling block.

Ball Styling


#ball {

Targets the element with:


id="ball"

The # symbol means "ID selector".


width: 50px;

Ball width = 50 pixels.


height: 50px;

Ball height = 50 pixels.


background: red;

Makes the ball red.


border-radius: 50%;

Turns the square into a circle.

Without:

████
████

With:



position: relative;

Allows the element to move using top, left, etc.

The animation changes the top value.

Animation Property


animation: bounce 1s infinite alternate ease-in-out;

This is shorthand for several animation settings.

bounce

The animation name.

It matches:


@keyframes bounce

1s

Animation lasts 1 second.

infinite

Repeat forever.

alternate

Instead of restarting:

0 → 200
0 → 200
0 → 200

it goes:

0 → 200
200 → 0
0 → 200

So the ball moves up and down.

ease-in-out

Makes movement smoother.

Instead of:

constant speed

it does:

slow start
fast middle
slow stop

More natural motion.

3. Keyframes Animation


@keyframes bounce {

Defines the animation called bounce.

Think of keyframes as instructions for what happens over time.

Starting Position


from {
top: 0px;
}

At the beginning:

top = 0

Ball is in its original position.

Ending Position


to {
top: 200px;
}

At the end:

top = 200

Ball moves 200 pixels downward.

Visual

Start:

🔴

End:





🔴

The ball drops 200 pixels.

Because of alternate, it then rises back up.

4. End of CSS


</style>

Ends the CSS section.


</head>

Ends the page header.

5. Page Content


<body>

Everything visible on the page goes here.


<div id="ball"></div>

Creates an empty box.

Because CSS styles it:

  1. 50×50 pixels
  2. Red
  3. Circular

it becomes the ball.


</body>
</html>

Ends the page.

What Happens When You Open It

  1. Browser loads the page.
  2. The body fills the screen.
  3. Flexbox centers the ball.
  4. The ball is drawn as a red circle.
  5. The bounce animation starts.
  6. The ball moves down 200px.
  7. The ball moves back up.
  8. Steps 6–7 repeat forever.

Animation Timeline

0.0s 🔴
0.5s 🔴
1.0s 🔴

1.5s 🔴
2.0s 🔴

(repeats)

The result is a smooth bouncing red ball in the center of the screen.

Add More Style!

You can change the ball color:


background: blue;

Or make it bigger:


width: 80px;
height: 80px;

Or make it bounce faster:


animation: bounce 0.5s infinite alternate;

Experiment and have fun.

Add JavaScript for Extra Movement (Optional Upgrade)

f you want the ball to move left and right too, add this inside <style>:


@keyframes bounceSideways {
from { left: 0px; }
to { left: 200px; }
}

Then update the ball:

css

#ball {
animation:
bounce 1s infinite alternate ease-in-out,
bounceSideways 2s infinite alternate ease-in-out;
}

Now the ball moves in two directions.

Save and Run

Save your file and double‑click index.html.

if you are using realtimeHTML it will appear instantly to the right of the code

Your animation should appear immediately.

If you want to share it:

  1. Upload the file to Instructables
  2. Add screenshots of your code
  3. Add a short video or GIF of the animation running


Conclusion

You just created your first HTML animation! This project teaches the basics of:

  1. HTML structure
  2. CSS styling
  3. CSS keyframe animations
  4. Optional JavaScript movement

You can build on this to make games, interactive pages, or more advanced animations.