All electromagnetic waves travel at the same speed in a vacuum, 3.0 × 108 m/s. In air the speed is almost the same, but in a denser substance such as glass or water the waves travel more slowly. Light in glass travels at roughly two thirds of its speed in a vacuum.
When a wave crosses into a new substance, its frequency stays the same, because the source sets the frequency. Wave speed = frequency × wavelength, so when the speed decreases the wavelength becomes shorter.
If the wave meets the boundary at an angle, one side of the wave front slows down before the other and the wave changes direction. This is refraction. A wave entering a slower substance bends towards the normal, and a wave leaving it bends away from the normal. A wave travelling along the normal slows down but does not change direction.
Different wavelengths are slowed by slightly different amounts. In glass, violet light is slowed more than red light, so it is refracted more. White light passing through a prism therefore spreads out into colours. This is called dispersion.