Answer
The terrestrial planets are denser because they are made from heavier elements.
Explanation :
The gas giants Jupiter and Saturn have low density because they mainly consist of Hydrogen and Helium. The ice giants Uranus and Neptune are also low density. They contain Hydrogen, Helium and the ices which are water, methane, ammonia and other like compounds. The four inner planets Mercury, Venus, Earth and Mars are much denser. They contain only small amounts of Hydrogen and Helium and are mainly heavier elements which are denser. The Earth contains about 30% Iron and Oxygen, 15% Silicon and 14% Magnesium plus other heavy elements.