This post explains How hydrogen bonding explains unusual density changes of water with changes in temperature. At the same time, it explains why water has its greatest density at a temperature of 4°C.
why water has its greatest density at a temperature of 4°C
Hydrogen bonding accounts for the physical properties of water, including its unusual density changes with changes in temperature.
When ice is warmed, the increased vibrations of the molecules begin to expand and stretch the hydrogen bond structure.
When ice melts, about 15 percent of the hydrogen bonds break and the open structure collapses into the more compact arrangement of liquid water.
As the liquid water is warmed from 0°C still more, hydrogen bonds break down, and the density of the water
At 4°C, the expansion of water from the increased molecular vibrations begins to predominate, and the density decreases steadily with further warming (Figure 1). Thus, water has its greatest density at a temperature of 4°C.