If you were to view the sun from the International Space Station, you'd see its true color...which is white. The reason the sun looks yellow during the day and orangey-red at sunrise and sunset is because we are seeing it through the filter of the atmosphere. This is one of those tricky ways in which light and our eyes change the way we perceive color, as is the case with so-called "impossible colors"...red-green and blue-yellow, pairs of hues whose light frequencies automatically cancel each other out in the human eye making them impossible to see simultaneously.
Sunlight isn't a single color of light but a combination "of the emission spectra of all the elements in the star." If you were to measure them, the peak output in the visible range would be in the green portion of the spectrum, not the yellow one. However, visible light isn't the only radiation emitted by the sun. Science tells us that "there's also blackbody radiation. The average of the solar spectrum is a color, which indicates the temperature of the sun and other stars.Our sun averages about 5,800 Kelvin, which appears nearly white. Out of the brightest stars in the sky, Rigel appears blue and has a temperature exceeding 100,000K, while Betelguese has a cooler temperature of 35,00K and appears red."
The atmosphere changes the apparent color of the sun by scattering light. This is commonly known as Rayleigh scattering. The scattering of short wavelengths of light by molecules in the atmosphere is what gives the sky its blue color. Here's how that scattering affects how we see the sun. At sunrise and at sunset, the atmosphere is thicker and makes the sun appear more orange or red. At midday, that layer of atmoshere is the thinnest so we see the sun closer to its true color (white) but still with a yellow tint to it. Smoke and smog also scatter light and makes the sun appear more orange and red but with less blue. This same effect makes the moon appear more red or orange when it is close to the horizon and more yellow and white when it is higher in the sky.
When you see NASA (National Aeronautics and Space Administration) images of the sun, you're viewing a false co,or image. The same is true when you see a photo taken from any telescope. Most often, the color that is chosen for that image is yellow because it is what's familiar to us. Photos taken with a green filter are usually left untouched. Why? That's because the human eye is most sensitive to green light (I keep telling you...green is good!) and can easily distinguish detail. But, if a neutral filter is used to observe the sun from Earth, either to protect the telescope or to view a solar eclipse, the sun will again appear yellow because the filter reduces the amount of light that reaches the eye but it doesn't change the wavelength. And I found this quite interesting, if you used that dame neutral filter out in space and didn't "correct" the image to make it look prettier, you would see the sun as it really is...white.
Yellow is a happy color and sunshine generally makes us all feel a bit better. Whatever the reason that we think of the sun as being yellow, I'm happy that we do.