When sunlight, which includes a spectrum of colors, enters Earth's atmosphere, the molecules of nitrogen and oxygen interact with the shorter wavelength components of visible light, primarily violet and blue light. The shorter wavelengths are more effectively scattered in all directions due to their higher energy. As a result, the scattered blue light is visible from various angles, giving the sky its characteristic blue appearance.
The other colours of the visible spectrum, such as red, orange, and yellow, have longer wavelengths and are scattered to a lesser extent. This is why we see these colors mainly during sunrise and sunset when sunlight has to travel through a longer path of atmosphere to reach our eyes. The additional atmospheric molecules it encounters increase the scattering of shorter wavelengths, leaving the remaining longer wavelengths to dominate, creating vibrant red and orange hues.