Almost everything gets denser as it cools and solidifies, so its solid form sinks in its own liquid. Water is a famous exception: as it cools toward freezing, its molecules lock into a hexagonal crystal held apart by hydrogen bonds, and that open structure makes solid ice about 9% less dense than liquid water. So ice floats.
This quirk has enormous consequences. When a lake freezes, ice forms on top and insulates the water below, so fish and other life survive the winter in liquid water beneath. If ice sank, lakes and even oceans would freeze solid from the bottom up, and aquatic ecosystems as we know them couldn't exist. A property that seems like trivia is actually a precondition for life in cold climates.
The reason water misbehaves comes down to the hydrogen bond, a weak attraction between the slightly positive hydrogen of one water molecule and the slightly negative oxygen of another. Linus Pauling, whose 1939 book systematized the chemical bond and helped earn him a Nobel Prize in Chemistry, showed how these directional bonds force water molecules into specific geometries. In liquid water molecules are jumbled and can pack fairly tightly, but as water freezes each molecule forms four rigid hydrogen bonds in a tetrahedral arrangement, spacing them farther apart in an open cage. That deliberate spacing — not random chance — is why ice is less dense, and why it floats on the water it came from.