Buoyancy
Fish have a swim bladder, a gas-filled sac. By adjusting the gas amount, they control buoyancy. More gas makes them more buoyant and they rise; deflating the bladder makes them sink.
Body Shape
The streamlined shape of a fish reduces water resistance, making it easier to swim and stay afloat.
Fins
Fins help fish maintain position in the water. Pectoral fins near the chest act like wings to help them stay upright and maneuver.
Movement
Continuously swimming helps keep fish afloat. When they stop moving, their bodies slowly begin to sink.
Density
A fish's body density is slightly less than water, meaning it displaces more water than its own weight, helping it stay afloat.
Let me know if you would like to learn more about any of these factors!