Why the sky is blue
Move the sun, thin the air, bend the physics, and watch the sky change in real time.
This sky is live
This isn’t a photo. Every pixel is sunlight, computed as it bounces through the air to you. Grab the sun.
The sun moves, but the sky stays blue everywhere you look, even far from the sun. Something in the air sends blue light at you from every direction.
For each pixel, the code follows a line of sight up through a curved, 60 km-deep atmosphere that thins out with height. At 16 points along it, it asks two questions. How much sunlight reaches this point? How much of that is scattered towards you?
It uses the same air and dust values as a widely used research model (Bruneton’s precomputed atmosphere). Molecular scattering at 440 nm is about 33 × 10⁻⁶ per metre. Air density halves roughly every 5.5 km of height.
Nothing is painted on. The blue haze on the distant ridges comes out of the same calculation.
Blue bounces
Sunlight holds every colour. Air molecules are far smaller than light waves, and they deflect short waves much more strongly: scattering goes as 1/λ⁴.
Without the colour bias, the sky turns white-grey. Air itself has no colour. The blue sky is sunlight, sorted by wavelength.
Violet light is shorter still, and at 400 nm it scatters about 9× more than 700 nm red. Two things tip the balance towards blue. The Sun puts out less violet than blue, and our eyes are much less sensitive to violet. The eye reads the scattered mix as blue with some white mixed in.
blue (450 nm) vs red (700 nm): (700 / 450)⁴ ≈ 5.9×
The 1/λ⁴ law holds for particles smaller than about a tenth of the wavelength, which includes the nitrogen and oxygen molecules in air. Lord Rayleigh published it in 1871. The slider here is a thought experiment: for real air the exponent is fixed at 4.
Sunset is what's left
At noon, sunlight crosses a thin slice of air. Near the horizon it skims through far more, losing blue all the way.
At the horizon the light crosses about 38× as much air as at noon. Nearly all the blue has been scattered away. What survives is red and orange.
Astronomers call this air mass. Straight up, it’s 1. At sea level, a widely used fit by Kasten and Young gives about 38 at the horizon:
X = 1 / (cos z + 0.50572 · (96.07995° − z)^−1.6364)
In this model, after 38 air masses about 15% of the red light gets through, but less than 0.01% of the blue. The swatch at the top shows the colour of that surviving sunlight.
Climb out of the blue
If the air makes the blue, then less air should mean less blue. Take the elevator up.
At 30 km, only about 2% of the air is left above you. With almost nothing to scatter it, the sky overhead goes nearly black. The glow below you is the atmosphere you just left.
Air density falls roughly exponentially with height, by a factor of e every ~8 km (its “scale height”). That gives about e^(−30/8) ≈ 2% at 30 km. The real profile varies with temperature, so treat the readout as an approximation.
Why clouds are white
Dust, smoke and water droplets are much bigger than air molecules. Big particles scatter every colour about equally.
The blue fades to a milky white, and a bright glow forms around the sun. Hazy skies look pale, and clouds look white, for the same reason.
When particles are about the size of a light wave or larger, the physics changes. This is Mie scattering, and it barely depends on colour. Cloud droplets are around 10 µm across, against 0.4–0.7 µm for visible light, so they scatter all colours alike and look white. These particles also scatter mostly forwards, which is why the glow hugs the sun.
Your sky
Everything is unlocked. Try a sunset from 20 km up, or a dusk with no colour bias. Drag the sun anywhere.
- Single scattering only: light that bounces more than once is ignored, so twilight is a little darker than reality.
- No ozone: real models include the ozone layer’s absorption, which shifts twilight colours a little.
- Three colours: red, green and blue stand in for the full spectrum.
- Auto-exposure: brightness adjusts like your eyes adapting.
- The sun’s disc is drawn about twice its real size so it shows up on a phone.
Other planets have other skies. On Mars, fine dust turns the daytime sky orange-red, and sunsets look blue-grey.