Why does ice have a lower density than water?
Due to the crystal structure of the solid phase of water, the molecules arrange themselves in a rigid, ordered fashion and end up being, on average, farther apart from each other (than they are in the liquid phase), and thus less dense. Less dense things float because of buoyancy.
I don't think that this question is still fully resolved, water is a fascinating molecule! But here are some thoughts.
Clearly, if ice is lighter than liquid water it is because it doesn't pack as well. Its an example of how a random-ish packing can be more efficient than an (non-closed packed) ordered packing of a "weirdly" shaped molecule. Imagine throwing LEGOs into a box, vs placing them very neatly, and orderly, two inches apart.
Why is this? To solidify the water should enter into a crystalline phase, but that requires accommodating the weird bonding angle of water (which is not quite tetragonal, which is easily packed. See C, Si, ect) in a way that can be made infinitely periodic, as compact as possible, and still satisfies the energy requirements. Largely due to this weird bonding angle, the resulting packing needs volume.
By contrast, in the liquid phase, the molecules do not have to be in specific sites. Rather, there is an attempt to maximize the hydrogen bonds. This leads (for example) to water chains. Meanwhile the thermal energy tries to scramble everything up, which breaks these chains up (average length of 7, if I recall).
Overall effect is that the water molecules in the liquid can put themselves into tight spaces, and stay long enough to make a difference, they can't in the ice phase.