Light from the sun is white. White light is composed of all of the colors visible to humans. As this light passes through the oxygen-rich atmosphere around the Earth, the short wavelengths of light that correspond to the colors violet and indigo are filtered out, and their wavelengths spread across the sky. At sunrise and sunset, when the sun is close to the local horizon, light must pass through more air before reaching the observer. This spreads light out more than usual, leaving primarily the longer wavelengths of yellow, orange and red to be seen.
Particles in the air can create a similar effect. Sometimes a volcanic eruption, industrial pollution or forest fire delivers large quantities of ash and dust to the upper atmosphere. This tends to darken the surface and scatter light in ways that turn the sky different colors.