Most solids, liquids and gases expand when they are heated because the molecules that make up the substance move more rapidly, which puts more distance between each of the molecules. This property of matter hold true irrespective of the state of matter in most cases. There are exceptions to this general rule; water, for example, expands when it transitions from liquid to solid form.
Temperature itself is a measure of the level of energy in a substance. This energy correlates with the rate at which the molecules in the material move. At any temperature above absolute zero, the molecules in a substance are moving. As the temperature rises, the molecules begin moving faster. The faster the molecules move, the greater the average distance between the molecules becomes. If the temperature rises high enough, the material transforms from the solid state to the liquid state. Because a liquid’s molecules are farther apart from each other than they are in a solid, the liquid does not keep its shape unless it is in a container. If the temperature rises even higher, the molecules move faster and become even more spread out. At this point, the substance becomes a gas, which also requires a container to retain its shape.