Stars are formed from dust and gas drawn together by gravity. As a protostar, increasing heat from compression leads to hydrogen fusion, forming a main sequence star. Over time, a star runs out of hydrogen fuel in its core and swells into a red giant. From there, a dying star will either cool into a white and then black dwarf, or for larger stars, explode as a supernova, throwing material containing heavier elements formed during its life into space. What remains is either a neutron star or, for the largest stars, a black hole.