Hydrostatic pressure - doesn't density vary with depth?

The density does increase with depth, but only to a tiny extent. At the bottom of the deepest ocean the density is only increased by about 5% so the change can be ignored in most situations.

If you're dealing with these sorts of depths you also need to take temperature into account because the water temperature changes with depth and the density also changes with temperature.


You said the right word: liquid!

$P=\rho g h$ holds only if the fluid that you are considering is not compressible, that is a liquid. Try to fill a syringe (without the needle) with some water, then close the hole and try to compress it: you will notice that you cannot do much, indeed liquids are not compressible, this mean that the density $\rho=m/V$ does not vary with pressure because the volume stays the same.

However when applying a physics relation it is important to understand its limits of validity. For instance if you compress water a lot you may even force the molecules to pack together and get ice, this will of course break the equation. But with liquids in everyday life that is just fine.


as the depth increases, wouldn't the density of the liquid increase because of the weight of the liquid above it compressing it?

No, it doesn't - or at least only negligibly so. At normal pressures, liquids are essentially incompressible. This table gives the compressibility of some liquids, including water. Note that the units are to be multiplied by $10^{-11}$ per Pascal. For water you get 46ppm per atmosphere. In most cases that is negligible.