Things don’t need to be “solid” in order to have mass, and mass is what generates gravity.
Further, the gas giants actually *do* have solid cores (sort of; it kind of depends on what you mean by “solid”) in that their cores are really really strange forms of hydrogen.
Latest Answers