The sky is blue due to Rayleigh scattering, which is the dispersion of light by particles much smaller than the wavelength of visible light. The sun's light is composed of all the colors of the visible spectrum. The gas molecules scatter the higher energy (blue) portion of the spectrum more than the low energy (red) portion of the visible spectrum. Sunlight travels through a thicker atmosphere during sunrise or sunset, thus, the scattering of higher wavelengths of visible light, such as green and blue is greater than the shorter wavelengths, including red and orange, giving the sky around the sun a bluish appearance.
The Earth's atmosphere is composed of a mixture of gases and other particles held in place by the force of gravity. The most abundant gas in the atmosphere is nitrogen (78%), followed by oxygen (21%), then argon (0.9 %) and traces of other gases. There is also water in the form of vapor, and ice crystals and solid particles, such as dust, pollen, volcanic ashes and salt from the oceans. The lower atmosphere is densest than the upper atmosphere, as it gradually thins with altitude. The stratosphere, which lies above the troposphere, protects us from ultraviolet radiation from the Sun.
The Sun emits electromagnetic radiation. Electromagnetic radiation travels through space in the form of waves. The energy of the radiation varies depending on the frequency of the radiation. Higher frequency radiation corresponds to shorter wavelengths (more energetic) and lower frequency radiation corresponds to longer wavelengths (less energetic) radiation. The visible (wavelengths of 380-720 nanometers) part of the electromagnetic spectrum is what we're able to see when sunlight reaches us. All wavelengths of electromagnetic radiation travel at the speed of light, or at 299,792 km (186,282 miles) per second.
The light from the Sun, which is white, is made up of all the colors of the visible spectrum; red, orange, yellow, green, blue and violet. These colors have different wavelengths and frequencies. Red has the longest wavelength, lowest frequency and less energy. Violet, which is at the other end of the visible spectrum, has a shortest wavelength, higher frequency and higher energy. Light travels through in the vacuum space without being disturbed, but once it reaches the atmosphere of the Earth, light gets reflected or is scattered in the sky.
Why the sky is blue: Rayleigh scattering
The way in which light behaves in the atmosphere depends on the particles it comes across with. Big particles, such as water droplets and dust tend to reflect the light in different directions and the reflected light appears white because much of the wavelengths have been reflected. When light comes across particles of gas, which are smaller than the wavelength of visible light, it gets absorbed and then radiated in a different direction. The higher frequencies, such as blue light are absorbed more often than the lower frequencies of the visible spectrum.
The sky is blue due to Rayleigh scattering. When light reaches the Earth's atmosphere, it bounces off when it interacts with the molecules of gas and dust and water particles in the air. Some colors of light, such as the longer wavelengths of red and orange are able to go through the air; however, shorter wavelengths, such as blue light are scattered in all directions, thus, the sky acquires a bluish tinge. When the Sun is closer to the horizon, the light from the Sun must travel through a thicker atmosphere, thus, more wavelengths of light are scattered, such as green, yellow and orange, making the sun look redder.
During sunset, light colors are typically brighter than the sunrise colors due to a greater amount of atmospheric particles interacting with the sunlight. The ocean is blue because the the colors of the red part of the visible spectrum are absorbed more than the blue part, which is reflected back and is what reaches our eyes. According to science made simple, in outer space, the sky is dark so that light is able to travel through without anything to interact with, since there is no air.