If you see a galaxy through a telescope with the naked eye, it looks more like a dim gray smudge. The vibrant colors only show up when you take a long exposure image.
The color comes mostly from stars, there are so many of them in a galaxy that they all blend together into a blurry glow. There are also interstellar gasses which can be illuminated by starlight or block starlight.
Latest Answers