When light is incident on a medium, it interacts with the matter. The matter consists of separate energy levels (atomic, molecular, vibrational, rotational, etc various different kinds), with forbidden regions between them. If energy is provided (through heat, electricity, light, etc) that is more than the energy gap between the levels, excitation of the relevant particles occur, i.e., they absorb the provided external energy and jump to a higher energy level.
Now, simply speaking the following scenarios can occur:
There are many other aspects and there may be the combination of the above scenarios in the real world. Also, there are sometimes metastable states in the forbidden region, or the energy levels shift due to some perturbation or modification to the medium, which can change it’s nature from transparent to opaque and vice-versa.
For example, in glass, the light is actually absorbed for a moment (levels in forbidde region, energy time uncertainty) and reemitted so there is refraction (refer point 2 above), but the energy is not absorbed because in a larger time scale (larger compared to light frequency and time of transitions, so several orders of magnitude less than 1), the light energy is less than the energy levels. This momentary absorption and reemission is actually why the speed of light is slower in mediums.