Let us consider the case of ice and water. Solid form of water is less dense than the liquid form. At temperatures near 0 deg.water molecules start forming bonds with one another to form a crystal structure. The resulting strucutre creates a greater amount of space between molecules than there was when the molecules floated freely in liquid state. All that extra space between the molecules is why ice is less dense than liquid water, hence ice floats on water.
Hope this helps.