How to Make a Bouncing DVD Screensaver With HTML, CSS and JavaScript
The bouncing DVD logo is one of the best first animations to build. It is one HTML file and about twenty lines of JavaScript. You do not need to install anything or know how to code. Copy the file below, save it, and open it.

The complete code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Bouncing DVD Screensaver</title>
<style>
body { margin: 0; height: 100vh; background: #000; overflow: hidden; }
#logo {
position: absolute; left: 0; top: 0;
font: bold 60px Arial, sans-serif;
color: #00ff66; padding: 0 12px;
}
</style>
</head>
<body>
<div id="logo">DVD</div>
<script>
const logo = document.getElementById("logo");
const colors = ["#ff3344", "#ffb000", "#00ff66", "#33ccff", "#ff4dd2", "#ffffff"];
let x = 50, y = 50; // where the logo is
let dx = 2, dy = 2; // how far it moves each frame
let colorIndex = 0;
function changeColor() {
colorIndex = (colorIndex + 1) % colors.length;
logo.style.color = colors[colorIndex];
}
function move() {
const maxX = window.innerWidth - logo.offsetWidth;
const maxY = window.innerHeight - logo.offsetHeight;
x += dx;
y += dy;
if (x <= 0 || x >= maxX) { dx = -dx; x = Math.max(0, Math.min(x, maxX)); changeColor(); }
if (y <= 0 || y >= maxY) { dy = -dy; y = Math.max(0, Math.min(y, maxY)); changeColor(); }
logo.style.transform = "translate(" + x + "px, " + y + "px)";
requestAnimationFrame(move);
}
move();
</script>
</body>
</html>
How to use this code
- Get the file. Press Download above the code to save it as
dvd-screensaver.html. Or press Copy code, paste it into a plain text editor (Notepad on Windows, TextEdit in plain-text mode on a Mac, or a code editor such as VS Code) and save it asdvd-screensaver.html. The name must end in.html, not.txt. - Open it. Double-click the file. It opens in your web browser and starts working straight away.
- Change it. Open the same file in the text editor, edit something, save, and refresh the browser page to see the result.
Nothing needs to be installed, and the file works without an internet connection.
How the code works
The file has three parts: HTML for what is on the page, CSS for how it looks, and JavaScript for the movement.
The HTML
There is only one visible element: <div id="logo">DVD</div>. The id is a name, so the CSS and JavaScript can find it.
The CSS
background: #000makes the page black, andoverflow: hiddenstops scrollbars appearing.position: absolutelets the logo be placed anywhere on the page instead of sitting in the normal text flow.
The JavaScript
xandyare the logo's position in pixels from the top-left corner.dxanddyare how far it moves each frame. Positive means right or down; negative means left or up.maxXandmaxYare the furthest the logo can go: the window size minus the logo's own size.- When the logo reaches an edge,
dx = -dxflips its direction. That single line is the "bounce". changeColor()moves to the next colour in the list. The%sign wraps back to the first colour after the last.requestAnimationFrame(move)asks the browser to runmoveagain before the next screen refresh, about 60 times a second. That repeating call is the animation.
Easy changes to try
| To change | Edit this |
|---|---|
| The text | Replace DVD between the div tags with your name |
| The speed | Change dx = 2, dy = 2 to 4 for faster, 1 for slower |
| The size | Change 60px in the font line |
| The colours | Add or remove colour codes in the colors list |
| The background | Change #000 to another colour code |
Use a picture instead of text
Put an image file in the same folder and replace the div with <img id="logo" src="logo.png" width="200">. The movement code works without changes. The colour change only affects text, so it will have no visible effect on a picture.
Count corner hits
A corner hit is when both edges are reached in the same frame. Inside move, after the two if lines, you can test whether both bounces happened and add one to a counter. Our live version does this.
FAQ
Can I download the bouncing DVD screensaver code?
Yes. Use the Download button above the code to save it as an HTML file, or copy it and save it yourself. It is free to use and change.
Will the logo ever hit the corner?
It depends on the window and logo size. Some sizes produce regular corner hits and others never do. Resize the window to change the path.
How do I make it full screen?
Press F11 in the browser, or Control+Command+F on a Mac.
Hacker Typer
Hacker Typer 2.0
Hacker Simulator
Fake Hacker Screen
Hacker Typer Prank
Fake Command Prompt
Fake Linux Terminal
FBI Hacker Screen