The sky appears blue due to Rayleigh scattering, where shorter blue light wavelengths scatter more than other colors as sunlight passes through the atmosphere. During sunrise and sunset, the sun's rays pass through more of the atmosphere, scattering blue light away and allowing longer red and orange wavelengths to dominate. This creates the vibrant colors seen at these times.