A body floats or sinks in a liquid due to the difference in their:
Densities
Whenever a body is immersed in a liquid, it experiences an upward force. The magnitude of the upward force depends upon the density of the liquid. It is due to the difference in densities of the body and the fluid that makes the body float or sink.