Skip to content
The Chat Archive
gemini-2.5-pro-preview-03-25· Google LMArena Human Preference 140K

Create a realistic rendition of our solar system using html, css and js. Make it…

  1. User

    Create a realistic rendition of our solar system using html, css and js. Make it stunning! reply with one file.

  2. Assistant

    Okay, here is a single HTML file containing the HTML structure, CSS styling, and JavaScript logic to create a visually appealing, animated rendition of our solar system.

    Key Features:

    • Relative Sizes: Planets are sized relatively correctly (though exaggerated for visibility).
    • Relative Orbital Speeds: Planets orbit at speeds relative to each other (inner planets faster, outer planets slower).
    • Orbital Paths: Subtle orbital paths are shown.
    • Planet Textures: Uses CSS gradients and shadows to give planets some texture and depth.
    • Sun Glow: The sun has a radiating glow.
    • Starry Background: A simple starry background is generated.
    • Responsiveness: Uses vmin units, so it adapts reasonably well to different screen sizes.
    • Pure JS Animation: Uses requestAnimationFrame for smooth animation without external libraries.

    Limitations:

    • Scale: Distances and sizes are NOT to actual scale (this is impossible on a screen while keeping everything visible).
    • Elliptical Orbits: Orbits are simplified to circles.
    • Axial Tilt/Rotation: Simple CSS rotation is used; no accurate axial tilt simulation.
    • Moons: Moons are not included for simplicity.
    • Lighting: Basic lighting is implied by gradients/shadows, not a dynamic light source simulation.
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Stunning Solar System</title>
        <style>
            :root {
                --sky-color-top: #000518;
                --sky-color-bottom: #192A45;
                --orbit-color: rgba(255, 255, 255, 0.1);
                --sun-size: 8vmin;
                --mercury-size: 0.8vmin;
                --venus-size: 1.8vmin;
                --earth-size: 2vmin;
                --mars-size: 1.2vmin;
                --jupiter-size: 5vmin;
                --saturn-size: 4.5vmin;
                --uranus-size: 3vmin;
                --neptune-size: 2.8vmin;
    
                /* Relative orbital periods (Earth days / 365 for simplicity) */
                /* Actual speeds are derived in JS based on these ratios */
                --mercury-period: 0.24;
                --venus-period: 0.62;
                --earth-period: 1;
                --mars-period: 1.88;
                --jupiter-period: 11.86;
                --saturn-period: 29.46;
                --uranus-period: 84.01;
                --neptune-period: 164.8;
    
                /* Base animation speed factor */
                --base-speed: 50; /* Lower is faster */
            }
    
            html, body {
                margin: 0;
                padding: 0;
                height: 100%;
                width: 100%;
                overflow: hidden;
                background: radial-gradient(ellipse at bottom, var(--sky-color-bottom) 0%, var(--sky-color-top) 100%);
                display: flex;
                justify-content: center;
                align-items: center;
            }
    
            .solar-system {
                position: relative;
                width: 90vmin;
                height: 90vmin;
                /* border: 1px solid red; */ /* Uncomment for debugging container bounds */
            }
    
            .star {
                position: absolute;
                background-color: white;
                border-radius: 50%;
                box-shadow: 0 0 5px white;
                animation: twinkle 5s infinite alternate;
            }
    
            @keyframes twinkle {
                0% { opacity: 0.5; transform: scale(0.8); }
                100% { opacity: 1; transform: scale(1); }
            }
    
            .sun {
                position: absolute;
                top: 50%;
                left: 50%;
                width: var(--sun-size);
                height: var(--sun-size);
                background: radial-gradient(ellipse at center, #fff1a8 0%, #ffca42 50%, #ff8c00 100%);
                border-radius: 50%;
                box-shadow: 0 0 6vmin 2vmin #ffca42, 0 0 10vmin 4vmin rgba(255, 165, 0, 0.5);
                transform: translate(-50%, -50%);
                z-index: 100; /* Sun on top */
            }
    
            .orbit {
                position: absolute;
                top: 50%;
                left: 50%;
                border: 1px dashed var(--orbit-color);
                border-radius: 50%;
                transform: translate(-50%, -50%);
                pointer-events: none; /* Orbits don't block clicks/hovers on planets */
            }
    
            .planet {
                position: absolute;
                top: 50%; /* JS will calculate precise top/left */
                left: 50%;
                border-radius: 50%;
                background-color: gray; /* Default */
                transform-origin: center center;
                animation: spin-self 10s linear infinite; /* Basic self-rotation */
                box-shadow: inset -0.5vmin 0.2vmin 0.5vmin rgba(0,0,0,0.5), /* Basic shadow */
                            0 0 0.5vmin rgba(255, 255, 255, 0.1); /* Slight highlight */
                cursor: pointer;
                transition: transform 0.2s ease-out; /* For hover effect */
            }
    
            .planet:hover {
                transform: scale(1.5); /* Enlarge on hover */
                animation-play-state: paused; /* Pause self-spin on hover */
                z-index: 101 !important; /* Bring hovered planet to front (needs !important due to JS z-index) */
            }
    
    
            @keyframes spin-self {
                from { background-position: 0% center; }
                to { background-position: 200% center; } /* Simulate rotation with gradient/texture */
            }
    
            /* --- Planet Specific Styles --- */
    
            /* Mercury */
            .mercury {
                width: var(--mercury-size);
                height: var(--mercury-size);
                background: radial-gradient(circle at 30% 30%, #d3d3d3, #888888);
                animation-duration: 3s; /* Faster spin */
            }
            .orbit-mercury {
                width: 15vmin; /* Diameter */
                height: 15vmin;
            }
    
            /* Venus */
            .venus {
                width: var(--venus-size);
                height: var(--venus-size);
                background: radial-gradient(circle at 70% 30%, #f8e5a1, #c5a658);
                animation-duration: 8s;
            }
            .orbit-venus {
                width: 22vmin;
                height: 22vmin;
            }
    
            /* Earth */
            .earth {
                width: var(--earth-size);
                height: var(--earth-size);
                background: radial-gradient(circle at 30% 70%, #a8d8f0, #4f8bba 50%, #2e5a88); /* Blueish */
                 /* Simple clouds overlay attempt */
                background-image:
                    radial-gradient(circle at 30% 70%, #a8d8f0, #4f8bba 50%, #2e5a88),
                    radial-gradient(circle at 60% 40%, rgba(255,255,255,0.4) 10%, transparent 50%),
                    radial-gradient(circle at 20% 30%, rgba(255,255,255,0.3) 5%, transparent 40%);
                background-blend-mode: screen;
                animation-duration: 5s;
            }
            .orbit-earth {
                width: 30vmin;
                height: 30vmin;
            }
    
            /* Mars */
            .mars {
                width: var(--mars-size);
                height: var(--mars-size);
                background: radial-gradient(circle at 30% 30%, #ff8c42, #c55a1e);
                animation-duration: 6s;
            }
            .orbit-mars {
                width: 40vmin;
                height: 40vmin;
            }
    
            /* Jupiter */
            .jupiter {
                width: var(--jupiter-size);
                height: var(--jupiter-size);
                background: radial-gradient(circle at 40% 60%, #e0d6c4, #b8a88e 50%, #8c7b68);
                background-image: /* Add stripes */
                    radial-gradient(circle at 40% 60%, #e0d6c4, #b8a88e 50%, #8c7b68),
                    linear-gradient(170deg, transparent 40%, rgba(194, 163, 131, 0.6) 45%, rgba(194, 163, 131, 0.6) 55%, transparent 60%),
                    linear-gradient(175deg, transparent 60%, rgba(231, 210, 189, 0.5) 63%, rgba(231, 210, 189, 0.5) 67%, transparent 70%);
    
                animation-duration: 3s; /* Faster spin */
            }
            .orbit-jupiter {
                width: 55vmin;
                height: 55vmin;
            }
    
            /* Saturn */
            .saturn {
                width: var(--saturn-size);
                height: var(--saturn-size);
                background: radial-gradient(circle at 45% 45%, #f0e5c2, #c5b88f);
                animation-duration: 4s;
            }
            .orbit-saturn {
                width: 70vmin;
                height: 70vmin;
            }
            /* Saturn's Rings */
            .saturn::before {
                content: '';
                position: absolute;
                top: 50%;
                left: 50%;
                width: 180%; /* Ring size relative to planet */
                height: 180%;
                border: 0.6vmin solid rgba(184, 164, 127, 0.6);
                border-left-color: transparent; /* Make it look tilted */
                border-right-color: transparent;
                border-radius: 50%;
                transform: translate(-50%, -50%) rotateX(75deg) rotateZ(0deg); /* Tilt the rings */
                box-sizing: border-box;
                box-shadow: 0 0 1vmin rgba(184, 164, 127, 0.3);
            }
    
    
            /* Uranus */
            .uranus {
                width: var(--uranus-size);
                height: var(--uranus-size);
                background: radial-gradient(circle at 30% 30%, #c0e0e0, #7fbfc4);
                animation-duration: 7s;
            }
            .orbit-uranus {
                width: 80vmin;
                height: 80vmin;
            }
    
            /* Neptune */
            .neptune {
                width: var(--neptune-size);
                height: var(--neptune-size);
                background: radial-gradient(circle at 70% 30%, #80a0f0, #3a5cac);
                animation-duration: 9s;
            }
            .orbit-neptune {
                width: 90vmin;
                height: 90vmin;
            }
    
            /* Tooltip for planet info */
            .tooltip {
                position: absolute;
                background-color: rgba(0, 0, 0, 0.7);
                color: white;
                padding: 5px 10px;
                border-radius: 4px;
                font-size: 0.8rem;
                font-family: sans-serif;
                white-space: nowrap;
                opacity: 0;
                visibility: hidden;
                transition: opacity 0.2s, visibility 0.2s;
                z-index: 110; /* Above everything */
                pointer-events: none; /* Don't interfere with hovering */
            }
    
            .planet:hover .tooltip {
               /* JS will position this */
            }
    
    
        </style>
    </head>
    <body>
        <div class="solar-system" id="solarSystem">
            <div class="sun"></div>
            <!-- Orbits and planets will be added here by JS -->
        </div>
    
        <div class="tooltip" id="tooltip"></div>
    
        <script>
            const solarSystem = document.getElementById('solarSystem');
            const tooltip = document.getElementById('tooltip');
            const body = document.body;
    
            const planetsData = [
                { name: 'Mercury', className: 'mercury', radius: 7.5, period: parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--mercury-period')), sizeVar: '--mercury-size', info: "Mercury: The swift planet." },
                { name: 'Venus', className: 'venus', radius: 11, period: parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--venus-period')), sizeVar: '--venus-size', info: "Venus: Earth's hot sister." },
                { name: 'Earth', className: 'earth', radius: 15, period: parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--earth-period')), sizeVar: '--earth-size', info: "Earth: Our home." },
                { name: 'Mars', className: 'mars', radius: 20, period: parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--mars-period')), sizeVar: '--mars-size', info: "Mars: The red planet." },
                { name: 'Jupiter', className: 'jupiter', radius: 27.5, period: parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--jupiter-period')), sizeVar: '--jupiter-size', info: "Jupiter: The gas giant." },
                { name: 'Saturn', className: 'saturn', radius: 35, period: parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--saturn-period')), sizeVar: '--saturn-size', info: "Saturn: The ringed jewel." },
                { name: 'Uranus', className: 'uranus', radius: 40, period: parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--uranus-period')), sizeVar: '--uranus-size', info: "Uranus: The ice giant." },
                { name: 'Neptune', className: 'neptune', radius: 45, period: parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--neptune-period')), sizeVar: '--neptune-size', info: "Neptune: The distant blue." }
            ];
    
            const baseSpeed = parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--base-speed'));
            const vminToPx = Math.min(window.innerWidth, window.innerHeight) / 100; // Calculate 1vmin in pixels
    
            // Create Stars
            const numStars = 200;
            for (let i = 0; i < numStars; i++) {
                const star = document.createElement('div');
                star.classList.add('star');
                const size = Math.random() * 2 + 0.5; // Star size between 0.5px and 2.5px
                star.style.width = `${size}px`;
                star.style.height = `${size}px`;
                star.style.top = `${Math.random() * 100}%`;
                star.style.left = `${Math.random() * 100}%`;
                star.style.animationDelay = `${Math.random() * 5}s`; // Randomize twinkle start
                body.appendChild(star); // Add stars directly to body for full background coverage
            }
    
    
            // Create Orbits and Planets
            planetsData.forEach((p, index) => {
                // Create Orbit Element
                const orbit = document.createElement('div');
                orbit.classList.add('orbit', `orbit-${p.className}`);
                orbit.style.width = `${p.radius * 2}vmin`; // Diameter
                orbit.style.height = `${p.radius * 2}vmin`;
                orbit.style.zIndex = index; // Ensure orbits stack correctly visually
                solarSystem.appendChild(orbit);
    
                // Create Planet Element
                const planet = document.createElement('div');
                planet.classList.add('planet', p.className);
                planet.dataset.info = p.info; // Store info for tooltip
                planet.style.zIndex = 10 + index; // Planets above orbits, stack based on distance
                solarSystem.appendChild(planet);
                p.element = planet; // Store element reference in data object
    
                 // Add tooltip events
                planet.addEventListener('mouseover', (e) => {
                    tooltip.textContent = planet.dataset.info;
                    tooltip.style.opacity = '1';
                    tooltip.style.visibility = 'visible';
                    // Position tooltip near mouse - adjust offsets as needed
                    tooltip.style.left = `${e.clientX + 15}px`;
                    tooltip.style.top = `${e.clientY - 25}px`;
                });
    
                planet.addEventListener('mousemove', (e) => {
                     // Update position while mouse moves over planet
                    tooltip.style.left = `${e.clientX + 15}px`;
                    tooltip.style.top = `${e.clientY - 25}px`;
                });
    
                planet.addEventListener('mouseout', () => {
                    tooltip.style.opacity = '0';
                    tooltip.style.visibility = 'hidden';
                });
            });
    
            // Animation function
            let startTime = Date.now();
            function animate() {
                const currentTime = Date.now();
                const elapsedTime = (currentTime - startTime) / 1000; // Time in seconds
    
                planetsData.forEach(p => {
                    const planetSizeVmin = parseFloat(getComputedStyle(document.documentElement).getPropertyValue(p.sizeVar));
                    const planetRadiusPx = p.radius * vminToPx;
                    const planetSizePx = planetSizeVmin * vminToPx;
    
                    // Calculate angle based on time and orbital period
                    // The division by p.period makes outer planets slower
                    // baseSpeed controls overall animation speed
                    const angle = (elapsedTime * (Math.PI * 2)) / (p.period * baseSpeed);
    
                    // Calculate position using trigonometry
                    // Center of the solarSystem container is (0,0) relative to itself
                    const x = planetRadiusPx * Math.cos(angle);
                    const y = planetRadiusPx * Math.sin(angle);
    
                    // Apply position:
                    // We need to translate from center-based coords (x,y) to top-left based CSS
                    // Center of solarSystem div is 50% 50%
                    // Offset by half the planet's size to center the planet on its orbital path
                    p.element.style.left = `calc(50% + ${x}px - ${planetSizePx / 2}px)`;
                    p.element.style.top = `calc(50% + ${y}px - ${planetSizePx / 2}px)`;
                });
    
                requestAnimationFrame(animate); // Loop the animation
            }
    
            // Start the animation
            animate();
    
            // Recalculate vminToPx on resize for responsiveness (optional but good)
            window.addEventListener('resize', () => {
                vminToPx = Math.min(window.innerWidth, window.innerHeight) / 100;
                 // Potentially redraw stars or adjust positions if needed,
                 // but the animation loop handles position recalculation based on new vminToPx
            });
    
        </script>
    </body>
    </html>
    

    How to Use:

    1. Copy the entire code block.
    2. Save it as an HTML file (e.g., solar_system.html).
    3. Open the file in your web browser.

    Enjoy your stunning (albeit simplified) solar system! You can tweak the CSS variables (--base-speed, planet sizes, colors, glow effects) to customize the appearance further.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.