Shine a light through a prism, or hang one in the window on a sunny day, and you'll see a rainbow. It's the same rainbow you see in the sky because, on a day with a mixture of rain and sun, each raindrop acts as a miniature prism. For physicists debating whether light is a wave or particle, this phenomenon is a strong argument for the former. In fact, experiments with prisms were central to Issac Newton's formulation of the theory of optics and the wave nature of light.
TL;DR (Too Long; Didn't Read)
White light refracts when it passes through a prism. Each wavelength refracts at a different angle, and the emergent light forms a rainbow.
Refraction and the Rainbow
Refraction is a phenomenon that happens when a beam of white light passes through the interface between air and a denser medium, such as glass or water. Light travels more slowly in a denser medium, so it changes direction – or refracts – when it passes through the interface. White light is a mixture of all the wavelengths of light, and each wavelength refracts at a slightly different angle. Therefore, when the beam emerges from the denser medium, it has been split into its component wavelengths. The ones you can see form the familiar rainbow.
The Index of Refraction
The angle of refraction in a particular medium is defined by its index of refraction, which is a property derived by dividing the speed of light in a vacuum by the speed of light in that particular medium. When light passes from one medium to another, the angle of refraction can be derived by dividing the indices of refraction of the two media. This relationship is known as Snell's Law, named for the 17th century physicist who discovered it.
Many other materials besides glass produce rainbows. Diamond, ice, clear quartz and glycerine are just some examples. The breadth of the rainbow is a function of the index of refraction, which varies directly with the density of the material. You can even see a rainbow when light passes from water through a clear crystal or piece of glass and back into water.
Colors of the Rainbow
Although we traditionally identify a rainbow by seven component colors, it's actually a continuum with no discrete boundaries from one hue to the next. It was Newton who arbitrarily split the spectrum into seven colors in deference to the ancient Greeks, who believed seven to be a mystical number. The colors are, in order from longest wavelength to shortest, red, orange, yellow, green, blue, indigo and violet. If you're looking for a way to remember the order, use the acronym ROYGBIV, pronounced roy-gee-biv, or try this mnemonic: ROY Gave Betti Violets.
The wavelength frequency increases as you proceed across the rainbow from red to violet. This means the energy of the individual photons – or wave packets – also increases, because the two are directly related by Planck's Law.