The density of water is not constant, it varies with temperature according to the following curve
As you can see, the density of water reaches its peak value at around
Notice that the absolute peak value reached by the density occurs at
This happens because of water malecule's ability to form hydrogen bonds with one another. At higher temperatures, water molecules have high average kinetic energies that overpower the hydrogen bonding.
This will cause greater molecular motion (collissions with neighbouring molecules, vibrations, etc.) for each water molecule, so the space occupied by individual molecules increases, leading to a decrease in density.
Likewise, at temperatures below freezing, the average kinetic energy of the water molecules will no longer overpower the hydrogen bonding and the molecules will be stuck in a crystal lattice structure.
Once again, the density will decrease because water molecules are now further apart from each other.
So why is water's density maximum at
and this very cool video from TED-Ed