The sun appears yellow to our eyes due to the way its light is scattered and absorbed by Earth's atmosphere. In reality, the sun emits light in all colors of the visible spectrum, which together create white light. However, as this light travels through the Earth's atmosphere, it undergoes a process called Rayleigh scattering.
Rayleigh scattering is the phenomenon where shorter wavelengths of light (blue and violet) are scattered more effectively by the molecules and particles in the atmosphere than longer wavelengths (red, orange, and yellow). As a result, when sunlight enters the Earth's atmosphere, the blue and violet wavelengths are scattered in all directions, making the sky appear blue to us.
Meanwhile, the longer wavelengths, particularly the yellow, orange, and red light, are less affected by scattering and are more likely to reach our eyes directly. As a result, during sunrise and sunset, when the sunlight has to pass through a thicker layer of the atmosphere, even more of the shorter wavelengths are scattered, leaving mostly the longer wavelengths visible to us. This is why the sun appears to have a yellow, orange, or red hue during these times.
During the rest of the day, when the sun is higher in the sky, the path of sunlight through the atmosphere is shorter, and less scattering occurs, making the sun appear more white or slightly yellowish.
It's important to note that the sun's color appearance can be influenced by other factors, such as atmospheric conditions, pollution, and even human perception. However, the primary reason the sun appears yellow is due to the scattering of light by Earth's atmosphere, favoring longer wavelengths during sunrise and sunset.