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.
The density of ice is 0.9167 g/cm3 at 0 C, whereas water has a density of 0.9998 g/cm at the same temperature. Liquid water is densest, essentially 1.00 g/cm , at 4 C and becomes less dense as the water molecules begin to form the hexagonal crystals of ice as the freezing point is reached.
In solid form (ice), the molecules form a crystal lattice whereby the molecules are spaced further apart.
Hence, ice has less molecules per unit volume, compared to water, so it is less dense. That is why it floats.