Light changes speed as it moves from one medium to another (for example, from air into the glass of the prism). This speed change causes the light to be refracted (bending of light) and to enter the new medium at a different angle. The degree of bending of the light’s path depends on the angle that the incident beam of light makes with the surface, and on the ratio between the refractive indices of the two media (Snell’s law). The refractive index of many materials (such as glass) varies with the wavelength or color of the light used, a phenomenon known as dispersion. This causes light of different colors to be refracted differently and to leave the prism at different angles, creating an effect similar to a rainbow.
In fact, tiny droplets of water in the atmosphere act as small prisms and creates a big RAINBOW.