It’s due to a phenomenon called diffraction. The sun is actually emitting white light which has a significant amount of blue-green waves along with other colors of the spectrum. The fusion process creates white light which after traveling to earth, turns yellow. It is a well-known scientific fact that white light is a combination of seven different colors.
Therefore, the sun emits light of all these seven colors hence, having pure white light. This whiteness of the sun is visible during the afternoon when the sun is directly overhead. And the rest is done by diffraction. What is responsible for diffraction, you ask? It is our very own atmosphere. Diffraction is defined as the bending of light waves on meeting an obstacle. Rainbows are a phenomenon that occurs when white light is diffracted by a raindrop.
The main principle behind diffraction is the wave nature of white light. The waves of different colored light have a different wavelength. An obstacle in its path splits the different colored waves of light because all colors have different wavelengths. Applying this concept to sunlight, the waves from the sun meet particles of the atmosphere and get diffracted.
This diffraction is inversely proportional to the fourth power of wavelength, which means that the higher the wavelength the lesser the scattering. This is called Rayleigh’s scattering law. Since blue has the least wavelength, it gets scattered the most giving the sky its well known blue color. By the time, we reach the yellow spectrum of light has travelled through the atmosphere and doesn’t scatter anymore, hence the sun appears yellow.
This is also the reason that during sunrise and sunset the sun appears red since light has to travel more distance when it comes from the horizon.