At the interface between two media, the fields must obey certain boundary conditions. This follows directly from the Maxwell equations. If the vector perpendicular to the surface boundary is [itex]\hat n[/itex], then, for example,
[tex]\hat n \cdot D_1 = \hat n \cdot D_2, \quad \hat n \times E_1 = \hat n \times E_2[/tex]
The use of the [itex]D[/itex] field in these conditions that the component of an EM wave that is perpendicular to the surface of the boundary can lengthen and shorten depending on how the permittivity changes. The component that is along the boundary will always stay the same, however. These effects put together constitute refraction.