Refraction of light occurs due to the different refractive indices of the medium in which the light travels.
Explanation:
The medium through which the light travels have different refractive indices, because of which the light rays crosses the boundary of the refractive indices. They are shifted from the travelling line according to the refractive index of the medium and hence, refraction is seen.
For example, air is medium with less refractive index as compared to glass, and therefore the light ray when enters into glass, travels slow and refracted from the actual path towards the normal of the ray.