Uranus and Neptune are called ice giants because they are smaller and compositionally different from Jupiter and Saturn, the gas giants. Jupiter and Saturn are composed of mostly hydrogen and helium, with large mantles of metallic hydrogen (which acts like a metal, due to the pressure and temperature within these planets) and only small cores of rock and ice. This is why they are called gas giants: They are mostly gaseous, with very little rock and ice.
Uranus and Neptune are composed of some hydrogen and helium, but they also contain heavier elements such as oxygen, carbon, nitrogen, and sulfur. Beneath their relatively thin outer shells of hydrogen and helium, these planets’ mantles are largely made of compressed, slushy water and ammonia. The ice giants’ rocky, icy cores are also proportionally larger than the amount of gas they contain, unlike the gas giants. This is why Uranus and Neptune are called ice giants.
The “ice giant” terminology took hold in the 1990s when researchers realized Uranus and Neptune were compositionally different from Jupiter and Saturn. Classifying them differently better reflects the variations in the formation of the outer planets, giving astronomers a clearer picture of how our solar system and others formed.