Creating a single-page HTML screensaver without using any text can be achieved by using simple HTML and CSS. Below is an example of a screensaver that features moving colored circles across the screen. You can copy this code into an HTML file and open it in your web browser to see it in action.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML Screensaver</title>
<style>
body {
margin: 0;
overflow: hidden;
background-color: #000; /* Black background */
}
.circle {
position: absolute;
border-radius: 50%;
opacity: 0.8;
animation: move 10s linear infinite;
}
@keyframes move {
0% {
transform: translate(0, 0);
}
100% {
transform: translate(calc(100vw - 50px), calc(100vh - 50px));
}
}
</style>
</head>
<body>
<script>
function createCircle() {
const circle = document.createElement('div');
circle.className = 'circle';
const size = Math.random() * 50 + 10; // Random size between 10px and 60px
circle.style.width = `${size}px`;
circle.style.height = `${size}px`;
circle.style.backgroundColor = `hsl(${Math.random() * 360}, 100%, 50%)`; // Random color
circle.style.top = `${Math.random() * (window.innerHeight - size)}px`; // Random starting position
circle.style.left = `${Math.random() * (window.innerWidth - size)}px`;
// Random animation duration
circle.style.animationDuration = `${Math.random() * 5 + 5}s`;
document.body.appendChild(circle);
// Remove circle after its animation
setTimeout(() => {
document.body.removeChild(circle);
}, 10000); // Matches the animation duration
}
// Create circles at intervals
setInterval(createCircle, 500);
</script>
</body>
</html>
Explanation:
- HTML Structure: The document contains a simple structure with
DOCTYPE, html, and head elements.
- CSS Styling:
- The body has a black background and hides overflow.
- A
.circle class is defined for the animated circles with random sizes and colors.
- The
@keyframes move animation defines the movement of the circles from the top-left to the bottom-right corner.
- JavaScript Functionality:
- The
createCircle function generates a circle with random size, color, and starting position. It also sets a random duration for the animation.
- A new circle is created every 500 milliseconds, and the circle is removed after its animation completes.
This screensaver will continuously generate colorful circles that animate across the screen. You can modify the parameters to create different effects if desired!