The light from the Sun looks white. But it is really made up of all the colors of the rainbow. We can see the different colors of the spectrum by splitting the light with a prism. The spectrum is also visible when you see a rainbow in the sky. A prism is a specially shaped crystal. When white light shines through a prism, the light is separated into all its colors.
The reason the sky is blue has to do with a concept called Rayleigh Scattering. Let’s say we have a gas, and we shine light on it. The light will hit the gas molecules, and get absorbed. Then, the gas molecules will emit the light back out at the same wavelength (color!), but in a new direction. Interestingly enough, blue light (shorter wavelength) gets absorbed more than red light (longer wavelength). This scattering of incoming light is Rayleigh Scattering!
Have you figured it out yet? Now imagine the sun, shining light towards the Earth. Remember, this is white light, which means it contains light of all visible colors at once! As the white light from the Sun hits the Earth’s atmosphere (a gas!), the molecules absorb and emit the blue light, and scatter it all around. So when you look up at the sky, you’re seeing all of this scattered blue light. But why is the sky paler near the horizon? At the horizon, light has to pass through more of the atmosphere, and in the same way blue light is scattered towards you, it ends up getting scattered away again, and so the other wavelengths are the ones that get through, since they are less affected by scattering.