When light passes through a transparent medium such as water or glass, the electrons slow down, which causes the light to refract. As light enters the transparent medium, the wavelength colors bend at different angles to create a rainbow. .
The speed that light will travel through a transparent medium, which is also referred to as the phase velocity, is dependant on the medium itself. For example, when a light travels through glass and then through water, the speed will change from one medium to the next while the frequency remains consistent throughout. This can be witnessed when a straw is placed in a glass of water. The straw appears to bend where it enters the water.