When heat leaves these substances, the molecules vibrate slower. The atoms can get closer which results in the matter contracting. Again, the mass is not changed. Sidewalks, bridges, telephone lines, railroad tracks, and other countless objects all expand on a hot summer day. They contract when they lose their heat.
Liquids expand when heated and they contract when cooled.
Ice however, expands when it freezes. As the water molecules lose heat, they vibrate less , and are able to form geometric patterns that take up more space . As the volume of ice increases, the density of ice decreases and the ice floats. Gases expand when heated and contract when cooled. For instance, a balloon will expand if it is left in a hot car.