This is an easy question to ask but the answer is pretty hard. The light that comes from the Sun to Earth looks white, but really it is made up of all different colors of light mixed together. You can see this by using a glass of water or a glass prism to break up sunlight into rainbows.
In the rainbow, red is on the outside and blue is on the inside. That’s because red light travels in long, slow waves and blue light travels in short, quick ones. As the Sun’s light travels through the air to get to your eyes, many of the light waves hit molecules of (mostly) oxygen and nitrogen in the air.
These molecules soak up the light energy, but mostly the blue light because it has shorter wavelengths and is more likely to hit them. Then they shoot out that light energy again, but in all different directions so it gets scattered all over, and you see it all over the sky.
Meanwhile, the longer wavelengths of light – red, yellow, orange – don’t get absorbed so much. More of them make it in a straight line from the Sun through the air to your eyes. That’s why the Sun looks yellow to you.
But violet – purple – moves in even shorter waves than blue. Why doesn’t the sky look purple? It’s true that the air molecules do scatter the purple light even more than the blue light. But there are three reasons why the sky looks more blue anyway: 1) the sun actually puts out less violet light than blue light, 2) our eyes are not as good at seeing the color purple as we are at seeing blue, and 3) the scattered light we actually see in the sky is mostly blue, with some violet on one end and some green on the other end. The violet and green cancel each other out so we see blue.