A phenomenon called Rayleigh scattering causes light from the Sun to bounce off tiny particles in the atmosphere and scatter in different directions. Sunlight consists of many different colours: from red, which has the longest wavelength of all visible light, through to violet at the blue end of the spectrum, which has the shortest wavelength. Due to this short wavelength, blue light is scattered more effectively than other colours, and this is why the sky normally appears blue to us.
At sunrise or sunset, however, when the Sun is low on the horizon, the light rays must pass through more of the atmosphere – and therefore bounce off more molecules – than at other times of day. This means that more blue light gets scattered away before the light reaches your eyes. Other colours – such as red, orange and yellow – can therefore continue to pass through the atmosphere unaffected, creating beautiful colours at the start and end of the day.