To understand how light travels from the sun to the Earth, you have to understand what light is. Light is an electromagnetic wave--a wave of electric and magnetic energy oscillating very quickly. There are many different electromagnetic waves, and the type is determined by the speed of oscillation. For example, radio waves oscillate more slowly than light, while X-rays oscillate much more quickly. These electromagnetic waves travel in small packets called photons. Because light travels in both waves and photon packets, it behaves both like a wave and a particle.
Traveling Through Space
Most waves require a medium to travel in. For example, if you drop a rock in a pond, it makes waves in the water. No water, no waves. Because light consists of photons, however, it can travel through space like a stream of tiny particles. The photons actually travel more quickly through space and lose less energy on the way, because there are no molecules in the way to slow them down.
When light travels through space from the sun, all of the frequencies of light travel in a straight line. When light hits the atmosphere, however, the photons begin to collide with gas molecules. Red, orange and yellow photons have long wavelengths and can travel right through the gas molecules. Green, blue and purple photons, however, have shorter wavelengths, which allows molecules to easily absorb them. The molecules hold onto the photon for only an instant, then shoot them out again in a random direction. This is why the sky looks blue. Many of these scattered photons fly toward the Earth, making the sky appear to glow. This is also why sunsets look red. At sunset, the photons have to travel through a larger layer of atmosphere before they reach your eyes. More of the higher frequency photons are absorbed, leaving layers of red, orange and yellow.