Water is an unusual and unique substance. Unlike most other compounds that continue to become denser as they grow colder, water only grows denser until it is just below the freezing point, then it actually grows less dense than it was originally when the freezing point is reached. To understand why water ice floats, though, we need to look at the properties of density.
With most compounds, when they are in solid form, the atoms in the molecules move only a short distance. As the solid is heated to fluid form, the atoms become more energetic and move a greater distance from each other. As a gas, they become the most expansive of all and are no longer held to the matrix of the solid or liquid substance.
In layman's terms, the hotter they become, the lighter they become because the same amount of the compound occupies a greater amount of space. In other words, at identical pressures, there are fewer molecules of the compound per volume of space, the warmer it becomes.
However with water, as mentioned at the beginning, the compound only grows denser until it is just above freezing. Then, as it gets even closer to the freezing point, it starts becoming less dense. At 0 degrees C or 32 degrees F, at standard pressure, the frozen water is less dense than the liquid water it came from.
Scientifically, but still basically, there are fewer molecules of H2O per unit volume at the freezing point than there are when it is in liquid form. Dense substances sink when placed in containers with the less dense form of the same substance. Thus, putting a solid bar of iron in a vat of molten iron will result in the iron bar sinking to the bottom, until it also melts.
Since water ice is less dense than liquid water, though, the liquid water basically sinks, resulting in the ice floating until it too melts. This is the mechanism that causes ice to float in water.
It is a great thing that this is true, too. If water ice was denser than liquid water, it would sink to the bottom and as more ice froze, it would simply compact on top of the ice that was already frozen. As a result, the earth would be a frozen ball from accumulated ice, and life most likely wouldn't have come to be. There simply would not be the amount of heat radiation from the sun or in the earth to keep the water from freezing solid.
Interestingly, this also means that impurities tend to precipitate out, being more dense than the frozen water, so ice at the north pole can be melted and can produce drinking water that is nearly free of salts, though it formed on the ocean surface, which has a high salt content.
Water has some remarkable properties, and not the least is how it changes density as it freezes. It allows ice to float in water, and at the same time prevents our planet from being a solid frozen ball.