Sure! Below is a single HTML file that creates a stunning, realistic rendition of our solar system using HTML, CSS, and JavaScript. It features:
- The Sun and 8 planets with relative sizes and orbital distances (scaled for screen).
- Smooth orbital animations.
- Planet textures/colors.
- Glowing Sun.
- Responsive and visually appealing design.
- Info tooltip on hover for each planet.
Open this file in any modern browser to see the solar system in action.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Realistic Solar System</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@500&display=swap');
* {
box-sizing: border-box;
}
body {
margin: 0;
background: radial-gradient(ellipse at center, #000010 0%, #000000 80%);
overflow: hidden;
height: 100vh;
font-family: 'Orbitron', sans-serif;
color: #eee;
user-select: none;
}
#solarSystem {
position: relative;
width: 100vw;
height: 100vh;
overflow: visible;
perspective: 1200px;
}
.sun {
position: absolute;
top: 50%;
left: 50%;
width: 140px;
height: 140px;
margin-left: -70px;
margin-top: -70px;
background: radial-gradient(circle at center, #fff200 0%, #ffae00 40%, #ff6f00 80%);
border-radius: 50%;
box-shadow:
0 0 30px 15px #ffcc33,
0 0 60px 30px #ffcc33,
0 0 90px 45px #ffcc33;
animation: sunPulse 6s ease-in-out infinite;
z-index: 1000;
}
@keyframes sunPulse {
0%, 100% {
box-shadow:
0 0 30px 15px #ffcc33,
0 0 60px 30px #ffcc33,
0 0 90px 45px #ffcc33;
}
50% {
box-shadow:
0 0 40px 20px #fff700,
0 0 80px 40px #fff700,
0 0 120px 60px #fff700;
}
}
.orbit {
position: absolute;
top: 50%;
left: 50%;
border: 1px solid rgba(255, 255, 255, 0.15);
border-radius: 50%;
transform-style: preserve-3d;
}
.planet {
position: absolute;
top: 50%;
left: 50%;
border-radius: 50%;
transform-style: preserve-3d;
box-shadow: inset 0 0 10px rgba(0,0,0,0.3);
cursor: pointer;
transition: transform 0.3s ease;
}
.planet:hover {
transform: scale(1.3);
z-index: 2000;
}
/* Tooltip */
#tooltip {
position: fixed;
background: rgba(0,0,0,0.75);
padding: 8px 12px;
border-radius: 6px;
pointer-events: none;
font-size: 14px;
color: #fff;
white-space: nowrap;
opacity: 0;
transition: opacity 0.3s ease;
z-index: 3000;
}
/* Planet textures/colors */
.mercury {
width: 8px;
height: 8px;
background: linear-gradient(135deg, #a19f9e, #6e6b6a);
box-shadow: 0 0 6px 1px #8a8887 inset;
}
.venus {
width: 14px;
height: 14px;
background: radial-gradient(circle at center, #e6d1a3, #b89e5a);
box-shadow: 0 0 8px 2px #d4b86a inset;
}
.earth {
width: 16px;
height: 16px;
background:
radial-gradient(circle at 40% 40%, #3a7bd5, #1e3f7f),
radial-gradient(circle at 70% 70%, #2a9d8f, #264653);
background-blend-mode: screen;
box-shadow: 0 0 10px 2px #2a9d8f inset;
}
.mars {
width: 12px;
height: 12px;
background: radial-gradient(circle at center, #b94e3f, #7a2e22);
box-shadow: 0 0 8px 2px #a03a2a inset;
}
.jupiter {
width: 40px;
height: 40px;
background:
radial-gradient(circle at 50% 50%, #d9b382, #a9744f);
box-shadow:
inset 10px 0 15px rgba(255,255,255,0.3),
inset -10px 0 15px rgba(0,0,0,0.3);
}
.saturn {
width: 36px;
height: 36px;
background:
radial-gradient(circle at 50% 50%, #e3d1a3, #a88f5a);
box-shadow:
inset 8px 0 12px rgba(255,255,255,0.3),
inset -8px 0 12px rgba(0,0,0,0.3);
}
.saturn-ring {
position: absolute;
top: 50%;
left: 50%;
width: 70px;
height: 20px;
margin-left: -35px;
margin-top: -10px;
border: 3px solid rgba(210, 180, 140, 0.7);
border-radius: 50% / 50%;
box-shadow: 0 0 10px 2px rgba(210, 180, 140, 0.5);
transform: rotateX(20deg);
pointer-events: none;
}
.uranus {
width: 28px;
height: 28px;
background: radial-gradient(circle at center, #a0d8ef, #4a90a4);
box-shadow: inset 0 0 10px 2px #7ec8e3;
}
.neptune {
width: 26px;
height: 26px;
background: radial-gradient(circle at center, #2a52be, #1b3a7a);
box-shadow: inset 0 0 10px 2px #1e3f7f;
}
</style>
</head>
<body>
<div id="solarSystem">
<div class="sun" title="Sun"></div>
</div>
<div id="tooltip"></div>
<script>
(() => {
const solarSystem = document.getElementById('solarSystem');
const tooltip = document.getElementById('tooltip');
// Data for planets: name, size(px), orbit radius(px), orbital period(days scaled), className, description
const planets = [
{
name: 'Mercury',
size: 8,
orbitRadius: 60,
orbitalPeriod: 88,
className: 'mercury',
description: 'Mercury: Smallest planet, closest to the Sun.'
},
{
name: 'Venus',
size: 14,
orbitRadius: 90,
orbitalPeriod: 225,
className: 'venus',
description: 'Venus: Hottest planet with thick toxic atmosphere.'
},
{
name: 'Earth',
size: 16,
orbitRadius: 120,
orbitalPeriod: 365,
className: 'earth',
description: 'Earth: Our home planet, supports life.'
},
{
name: 'Mars',
size: 12,
orbitRadius: 150,
orbitalPeriod: 687,
className: 'mars',
description: 'Mars: The Red Planet, potential for past life.'
},
{
name: 'Jupiter',
size: 40,
orbitRadius: 210,
orbitalPeriod: 4333,
className: 'jupiter',
description: 'Jupiter: Largest planet, gas giant with Great Red Spot.'
},
{
name: 'Saturn',
size: 36,
orbitRadius: 270,
orbitalPeriod: 10759,
className: 'saturn',
description: 'Saturn: Famous for its stunning rings.'
},
{
name: 'Uranus',
size: 28,
orbitRadius: 320,
orbitalPeriod: 30687,
className: 'uranus',
description: 'Uranus: Ice giant with a tilted rotation axis.'
},
{
name: 'Neptune',
size: 26,
orbitRadius: 370,
orbitalPeriod: 60190,
className: 'neptune',
description: 'Neptune: Farthest planet, known for strong winds.'
}
];
// Scale orbital period to animation speed (lower = faster)
// We'll use a base speed and scale inversely with orbital period
const baseSpeed = 0.02;
// Create orbits and planets
planets.forEach(planet => {
// Create orbit ring
const orbit = document.createElement('div');
orbit.classList.add('orbit');
orbit.style.width = orbit.style.height = planet.orbitRadius * 2 + 'px';
orbit.style.marginLeft = -planet.orbitRadius + 'px';
orbit.style.marginTop = -planet.orbitRadius + 'px';
solarSystem.appendChild(orbit);
// Create planet
const p = document.createElement('div');
p.classList.add('planet', planet.className);
p.style.width = p.style.height = planet.size + 'px';
p.style.marginLeft = -planet.size / 2 + 'px';
p.style.marginTop = -planet.size / 2 + 'px';
// Special case: Saturn ring
if (planet.name === 'Saturn') {
const ring = document.createElement('div');
ring.classList.add('saturn-ring');
p.appendChild(ring);
}
orbit.appendChild(p);
// Store references for animation
planet.orbitElement = orbit;
planet.planetElement = p;
planet.angle = Math.random() * 360; // random start angle
// Tooltip events
p.addEventListener('mouseenter', () => {
tooltip.textContent = planet.description;
tooltip.style.opacity = '1';
});
p.addEventListener('mouseleave', () => {
tooltip.style.opacity = '0';
});
});
// Animation loop
function animate(time = 0) {
planets.forEach(planet => {
// Increment angle based on orbital period
// Faster planets move more degrees per frame
planet.angle += baseSpeed * (365 / planet.orbitalPeriod);
if (planet.angle >= 360) planet.angle -= 360;
// Calculate position on orbit circle
const rad = (planet.angle * Math.PI) / 180;
const x = planet.orbitRadius * Math.cos(rad);
const y = planet.orbitRadius * Math.sin(rad);
// Apply transform to planet
planet.planetElement.style.transform = `translate(${x}px, ${y}px)`;
});
requestAnimationFrame(animate);
}
// Tooltip follow mouse
window.addEventListener('mousemove', e => {
tooltip.style.left = e.clientX + 15 + 'px';
tooltip.style.top = e.clientY + 15 + 'px';
});
animate();
})();
</script>
</body>
</html>
How to use:
- Save the above code as
solar-system.html.
- Open it in a modern browser (Chrome, Firefox, Edge).
- Hover over planets to see info tooltips.
- Watch the planets orbit the glowing Sun smoothly.
Enjoy your stunning solar system! 🌞🪐✨