Why are there colors on a rainbow?

Here is a more complete description:

https://www.physicsclassroom.com/class/refrn/Lesson-4/Rainbow-Formation

Because the various wavelengths of light coming from the sun and refracting toward your eyes through the wet air are bent through different angles.

To add to Damon's great description, each water droplet in the air acts as a tiny prism.

The colors on a rainbow are caused by the phenomenon of light refraction and dispersion. When sunlight passes through water droplets in the air, such as after a rain shower, it undergoes refraction, which is the bending of light.

To understand why colors appear, we need to know about one important property of light called dispersion. White light, such as sunlight, is actually made up of a combination of different colors of light, each with a different wavelength. When light passes through a medium, like water, the different colors of light bend at slightly different angles due to their varying wavelengths.

In the case of a rainbow, billions of water droplets in the air act like tiny prisms. As sunlight enters a water droplet, it bends and separates into its individual colors. The light then reflects off the inside surface of the droplet and exits, forming a cone-shaped beam of colors. When this beam hits our eyes, we see the different colors as a circular arc in the sky, creating a beautiful rainbow.

The colors of the rainbow are always in the same order: red, orange, yellow, green, blue, indigo, and violet. Red has the longest wavelength and violet has the shortest. This orderly sequence is a result of the varying angles of refraction and the different wavelengths of light.

So, in summary, the colors on a rainbow are produced because sunlight undergoes refraction and dispersion as it passes through water droplets in the air, causing the different colors of light to separate and form a visible spectrum.