The sky appears blue due to a phenomenon called Rayleigh scattering.
Rayleigh scattering is the scattering of light by particles that are much smaller than the wavelength of the light.
In the Earth's atmosphere, the main cause of Rayleigh scattering is the presence of nitrogen and oxygen molecules.
When sunlight reaches the Earth's atmosphere, it is composed of light of many different wavelengths, also known as colors. Blue light has a shorter wavelength and a higher frequency than other colors of light.
When the light encounters the nitrogen and oxygen molecules in the atmosphere, the molecules scatter the light in all directions. Because of the shorter wavelength and higher frequency of blue light, it is scattered more than other colors.
This scattering causes the sky to appear blue to us because the blue light is scattered in all directions and reaches our eyes from all over the sky. When we look at the sky, we see a greater concentration of blue light coming from all around the sky, making it appear blue.
At sunrise and sunset, the sun's light has to travel through more of the atmosphere before it reaches our eyes, which causes more scattering of the other colors of light. This is why the sky appears different shades of orange, pink, and purple at these times.
It's also worth noting that the color of the sky can vary depending on the concentration of certain air pollutants and particles in the atmosphere, which can cause the sky to appear hazy or gray.
Source- Internet