So initially all the colors came from the sun. The sunlight is visible white. Though sunlight consists of all colors of the rainbow! If you know that the light on earth is only a small part of the light energy in the universe! Cool!
When the white light coming from the sun radiates through the atmosphere layer, the light collides with molecules in the air. At the time of the collision, different colors or wavelengths of light are scattered with different amounts. The blue light (which has shorter wavelengths) is spread out more than red light (which has a longer wavelength).
When the sun is in the sky and its light passes through the layer of the atmosphere, the blue light is spread in all directions. Blue light is spread in all directions by small molecules of air in the Earth's atmosphere. The blue color is more scattered than other colors because of the smaller wavelength. In addition, light is also reflected and scattered by the surface of the earth. All this scattering is mixed and therefore we see the blue sky!
Why the blue sky has been answered. Now, if the sunset and sunrise it's orange sky, that's how?
The explanation is that the position of the lower sun causes the light to pass through more atmospheric layers before the light reaches your eyes! Which means most of the blue light has been scattered and the only remaining red is red. The result is like a beautiful panorama of colors as we watch the moment of sunset and sunrise.
You can also try experiments to find out, can be done with experiments using a special crystal-shaped prism illuminated by light.
When white light passes through a prism, the light is divided into all colors. All light goes on a straight line unless something is inhibited and can make the light reflected (like a mirror), deflected (like a prism) or propagated (like a gas molecule in the atmosphere).
When you see the rainbow there are various colors from red to purple. Yet in relation to the wavelength, the purple color has the shortest wavelength. Well, if the shorter the wavelength the more easily dissipated in the sky, why we do not see the sky purple?
The answer depends on our eye reaction to light! Inside our eyes, there are two types of cells that react to light. The stem portion of the cell is sensitive to the brightness of the light and the three cones on the cell are responsible for detecting color.
These three cones are sensitive to light of a certain wavelength. Blue cones are more sensitive to blue than purple. So when we look at the sky, indirectly the cells in the eye provide information to our brain that the colors we see are blue. So that's why the sky is blue.