The ability of objects to float, or buoyancy, comes from relative densities of the object and the fluid medium, whether it is water, air, or another liquid. When an object is immersed in fluid, it displaces an equivalent mass.
As an example, a balloon filled with helium will be less dense than the surrounding atmosphere. Some of the atmosphere is displaced below the balloon and exerts an upward force, causing it to float. As the density of the floating balloon increases, its buoyancy decreases and it will eventually succumb to gravity. Different fluids have different densities; for example, air is much less dense than water.