Light always takes the shortest path possible through any
medium.
As such, when it travels through a vacuum, it travels in a
straight line (no refraction).
When it travels through the air, the molecules in the air
scatter it very slightly, causing some diffusion and refraction,
depending on the composition of the air through which it
passes.
When it travels through water, the shortest path through that
medium is not a straight, collinear line from the point of
incidence...it is actually offset by a small angle (the angle of
refraction). The bent path that light takes through water or
another substance is actually the shortest path available to it
through that medium.