Matter expands in response to temperature due to an increase in kinetic energy—vibration—of molecules/ atoms. Gases expand the most, followed by liquids, then solids.
Expansion, more specifically thermal expansion, is the tendency of objects to expand—change in shape, area, and/ or volume, in response to a change in temperature.
An increase in temperature results in an increase in kinetic energy in a system, and this increase in kinetic energy of molecules translates to an observable expansion of an object. Expansion can be seen as an increase in separation between atoms. This occurs because of an increase in vibration in them, caused by the increase in kinetic energy when the temperature was raised.
All matter, to some extent, undergoes thermal expansion—some more prominently than others. In general, the following gives the three phases of matter in order of increasing potential to expand:
solid < liquid < gas.
That is, gases expand more, followed by liquids, and then solids.
Gases have molecules that are already energetic. They move around and occupy every available space in a container/ vessel. Consider a balloon filled with helium. Increasing the temperature would cause the gas molecules to move faster, hitting the walls of the ballon harder, and ultimately expanding it. You can also see the reverse happening when you put a balloon into a freezer—you lower temperature, which lowers kinetic energy, and the volume decreases.
The same applies to both liquids and solids, although to a lesser extent. In both cases, atoms and molecules are closer to each other and have stronger interactions than in gases. The interaction is stronger in solids, making expansion less prominent. Expansion still happens, though. Train tracks have gaps in them (of a few centimeters) to allow for thermal expansion.