Almost all the substances expand due to application of heat and contract for the extraction of heat. When a body is heated the heat energy and as such the kinetic energy of each molecule of the body increases. In solids the molecules vibrate with enhance energy against the intermolecular force and as a result the displacements of the molecules from their equilibrium position increase. But during displacement of a molecule from its equilibrium position a force of attraction is exerted on it.
When the molecule tends to go near to its neighboring molecules then a repulsive force acts on it. Again with the increase of intermolecular distance a force of attraction acts on the molecule. For the increase in temperature the molecules of a solid vibrate but it is not a simple harmonic oscillation.
Because, if the distance between two molecules is lessened than the distance in their equilibrium position then the repulsive force increases rapidly. But as the distance between two molecules relative to their equilibrium position increases, then the attractive force increases. But it does not happen as quickly as in the case of repulsive force.
As a result due to increase of temperature when the molecules of a body vibrate at a random fashion they approach further towards the exterior than towards the interior. As such the average equilibrium position of each molecule gets displaced towards the exterior and the body expands. Since intermolecular force is less in liquids, expansion due to heat is more in it.
For gaseous substances with the increase of temperature the random motion of the molecules increases. The thermal expansion of gases is maximum. The expansion of liquid is lower than that of gas and expansion of solid is the least.