The density of a planet is determined by its composition. Rocky planets like Earth and Mercury are denser than gas giants like Uranus and Saturn.