This is because the sun's rays are scattered by atmospheric molecules and particles suspended in the atmosphere. The blue of the sky can only be seen at low altitude, with the increase in height, as the air becomes thinner and thinner, the number of atmospheric molecules decreases dramatically, the molecules scattered light gradually weakened, the brightness of the sky is getting darker and darker, to a height of more than 20 kilometers, the role of the scattering
According to scientists, the determination of the wavelengths of blue light and violet light is relatively short, equivalent to a " small wave"; orange light and red light wavelength is longer, equivalent to "big wave". When encountering obstacles in the air, the blue light and violet light, because they can not go over those obstacles, will be "scattered" everywhere, covering the entire sky. This is how the sky is "scattered" into blue color. The scientist who discovered this "scattering" phenomenon is called Riley, who discovered it 130 years ago, and he is also a Nobel Prize winner. With the "scattering" phenomenon, you can explain the following celestial phenomena. For example, the sky above your head is blue, but at the horizon - where the sky meets the earth - it looks almost white. Why? It is because the sunlight has to travel much farther through the air from the horizon to your place than if it were to fall straight down from the sky - and naturally, it passes over many more microparticles along the way. These large numbers of microparticles thus scatter light many times over, so that it appears to be a pale blue in white.
Suggest you do a little experiment to verify this: take a glass of water, put it in a dark background, put a drop of milk in it, and then take a flashlight and shine it on the end of the glass, and get close to it, and the light from the flashlight will show up as a light blue color in the water. If you put more milk into the water, the whiter the water becomes, because the light is repeatedly scattered by these many milk particles, and the result is white. The reasoning is the same as it is white over the horizon. It is the same reason that in the evening when the sun is setting, the sky becomes red instead of blue, and the falling sun becomes dark red. Because of the many particles that the evening light encounters on its way to your place, the violet and blue parts of the sunlight are scattered in all directions, leaving only a little of the orange-red rays visible to your eyes - because of their long wavelength.
If sunlight shines down from the sky, it runs into certain obstacles continuously -- even when it's not raining. That's because the air that the light must penetrate is not empty; it consists of many, many tiny particles. Most of these, 99 percent, are either nitrogen or oxygen, while the rest are other gaseous particles and tiny floating particles that come from automobile exhaust, factory fumes, forest fires, or ash from volcanic eruptions. Although oxygen and nitrogen particles are a million times smaller than a drop of rain, they can still block the path of the sun. Light bounces off these numerous small "stumbling blocks" and changes its direction: light is scattered, as we chemists and physicists say. Blue and violet light, which have short wavelengths, scatter more than orange and red light, which have long wavelengths. So there is almost 10 times more violet light than red light in the scattered light, and almost 6 times more blue light than red light. The green, yellow and orange light can't beat the dominant blue and violet light, so we think that this scattered light is blue - sky blue. It was the British physicist and Nobel Prize winner Lord Riley who discovered this 130 years ago: when light traveling through air deviates from its original straight line direction, the light has a different wavelength and deviates by a different distance. Later, people called this scattering process Riley scattering in order to honor him. If you look up into the sky, you see mostly the scattered blue light from the sunlight, not the unscattered sunlight.