The colors of the sunset result from a phenomenon called scattering, says Steven Ackerman, professor of meteorology at UW-Madison. Molecules and small particles in the atmosphere change the direction of light rays, causing them to scatter. https://www.sciencedaily.com/releases/2007/11/071108135522.htm
Scattering also explains the colors of the sunrise and sunset, Ackerman says.
“Because the sun is low on the horizon, sunlight passes through more air at sunset and sunrise than during the day, when the sun is higher in the sky. More atmosphere means more molecules to scatter the violet and blue light away from your eyes. If the path is long enough, all of the blue and violet light scatters out of your line of sight. The other colors continue on their way to your eyes. This is why sunsets are often yellow, orange, and red.”
And because red has the longest wavelength of any visible light, the sun is red when it’s on the horizon, where its extremely long path through the atmosphere blocks all other colors. https://www.sciencedaily.com/releases/2007/11/071108135522.htm