A gas expands more than a liquid when it is heated. A gas will completely fill the container it is in, no matter how big it is. Picture a roomful of people running about. If you heat them up and they start moving faster, they will run faster, crashing into the walls harder. If you give them a room twice as big, they will fill that room also! If they are trapped in a small room, they will crash hard into the walls (with more pressure) and seek any opportunity to get out, possibly breaking the walls. This is what the molecules of a gas do when heated up.
When matter cools, it contracts. Contraction occurs because molecules move slower when a solid, liquid, or gas is cooled, and the cooler molecules move closer together. As the molecules move closer together, the matter gets smaller. Materials contract at different speeds and different amounts. Just like expansion, the amount of contraction depends on the composition of the material and on how much the temperature decreases.
Have you ever been told not to put a hot glass casserole dish or coffee pot into cold water because it might break? Or have you ever been told not to fill an ice-cold glass with boiling water because it might break? The glass would break because of thermal expansion and contraction. If one part of a piece of glass is heated or cooled more rapidly than the rest, the glass can crack or shatter. Special heat-resistant glass (such as “Pyrex”) has been developed that contracts and expands very little with changes in temperature.