A body floats or sinks in a liquid is due to the difference in their:
Densities
Whenever a body is immersed in a liquid, it experiences an upward force. The magnitude of this upward force depends upon the density of the liquid.
So, it is due to the difference in density of body and fluid, it either floats or sinks.