This document explains how to use and customize the animated twinkling stars background for your streaming overlay.
This HTML/CSS/JavaScript file creates a beautiful animated background with twinkling stars of various sizes, colors, and brightness levels. It’s designed specifically for streaming overlays and can be used as a base layer in OBS Studio or similar streaming software.
This document explains how to use and customize the animated twinkling stars background for your streaming overlay.
.html
extension (e.g., twinkling-stars-background.html
).The background can be easily customized by editing the HTML file in any text editor. Here are the main aspects you can change:
Find the body
CSS style in the <style>
section:
body {
width: 100vw;
height: 100vh;
overflow: hidden;
/* CUSTOMIZE: Background color - currently a dark blue gradient */
background: linear-gradient(to bottom, #0f0f29, #000011);
}
You can change the gradient colors to any color values you like. Some examples:
background: linear-gradient(to bottom, #2e1065, #000000);
background: linear-gradient(to bottom, #0c1445, #000000);
background: linear-gradient(to bottom, #300a0a, #000000);
Find the config
object in the JavaScript section:
const config = {
totalStars: 200, // Total number of stars
smallStarSize: 2, // Size of small stars in pixels
mediumStarSize: 3, // Size of medium stars in pixels
largeStarSize: 4, // Size of large stars in pixels
minTwinkleDuration: 3, // Minimum twinkling animation duration in seconds
maxTwinkleDuration: 8, // Maximum twinkling animation duration in seconds
minBrightness: 0.5, // Minimum star brightness (0-1)
maxBrightness: 0.9, // Maximum star brightness (0-1)
// CUSTOMIZE: Color variations for stars (hex codes)
// Default is white, you can add blue, yellow, etc.
colors: [
'#ffffff', // White
'#fffacd', // Light yellow
'#e6e6fa', // Lavender
'#b0e0e6' // Light blue
]
};
Here’s what each property does:
You can change the ratio of small, medium, and large stars by editing the getRandomSize()
function:
function getRandomSize() {
const rand = Math.random();
// 70% small, 20% medium, 10% large
if (rand < 0.7) {
return config.smallStarSize;
} else if (rand < 0.9) {
return config.mediumStarSize;
} else {
return config.largeStarSize;
}
}
The function uses probability thresholds to determine star sizes:
rand < 0.7
: Creates small stars (70% probability)rand < 0.9
: Creates medium stars (20% probability)To change the distribution, modify the threshold values using this formula:
if (rand < 0.33) {
return config.smallStarSize;
} else if (rand < 0.66) {
return config.mediumStarSize;
} else {
return config.largeStarSize;
}
if (rand < 0.1) {
return config.smallStarSize;
} else if (rand < 0.9) {
return config.mediumStarSize;
} else {
return config.largeStarSize;
}
if (rand < 0.5) {
return config.smallStarSize;
} else if (rand < 0.95) {
return config.mediumStarSize;
} else {
return config.largeStarSize;
}
If you want the stars to have a slight drifting motion, you can add this to the CSS:
@keyframes drift {
0% {
transform: translateY(0);
}
50% {
transform: translateY(5px);
}
100% {
transform: translateY(0);
}
}
.star {
/* Add to existing star CSS */
animation: twinkle var(--twinkle-duration) ease-in-out infinite,
drift 20s ease-in-out infinite;
}
For a more dynamic background, you could add code for occasional shooting stars. This would require additional JavaScript and CSS, but can create a more immersive effect.
totalStars
value.If the background doesn’t appear:
This background should work with:
This twinkling stars background is free to use for your personal or commercial streaming needs. No attribution is required, though it’s appreciated if you share where you got it from with other streamers!