Why is the sky blue?

It is actually a little bit on the violet side. It only looks blue because your eyes are much more sensitive to blue light than to violet light.

When white light from the sun travels through clear air, it hits the molecules of nitrogen and oxygen, and gets scattered a little bit, so it travels in a slightly different direction. Since there is miles of air between you and the sun, the light will scatter many times.

But how much the light is scattered depends on the color. Blue light is scattered about 10 times more than red light. This is called Rayleigh scattering after the man who worked out the math. Violet light is the light that is scattered the most, out of all the light our eyes can see.

This is why the sun looks yellow to us. White light from the sun will look yellow if we remove the violet light by scattering it away.

But our eyes are not very sensitive to violet light. They are very sensitive to blue light. They are also sensitive to green light and red light. A little bit of the violet light excites the red light sensing cones in our eyes, which is why violet looks like blue with a little red in it. It is also why the sky looks light blue instead of deep blue.

When the sun is near the horizon, there is more air between it and your eyes. The light near the sun has more red and yellow scattered because light that is scattered only one or two times does not change direction much. There is also more dust and smog, which scatter more red and yellow light. So sunsets are red, yellow, orange, and pink.