Refracting prisms take advantage of the fact that light makes changes in direction when passing from one material to another, but that different wavelengths bend different amounts. Thus, prisms can split white light, which is actually light made up of multiple wavelengths, coming in at one angle into its constituent colors going out at different angles. They can also do the opposite, condensing multiple color rays into one white ray.
Every transparent solid has its own refractive index, a number referring to the degree to which it bends light entering or leaving it. This bending is lowest for the longest wavelengths and increases the shorter the wavelengths. In visible light, red light is bent the least and violet light the most. This creates a rainbow effect on the outgoing light, with each color visible as a layer next to the colors that are adjacent in wavelength.
This tendency to refract light more at higher frequencies is actually not universal, but dependent on the nature of the materials. However, it holds true for most prisms within the visible light spectrum. The bending of light is actually dependent on how much the light is slowed, and each material actually has one or more wavelengths it bends the most because their frequencies match the resonant frequencies of the prism's constituent particles.