Stars are born in a cloud of dust and gas (mostly hydrogen & helium ) called a nebulae.
Gravity causes the denser regoins of the cloud to contract very slowly into clumps. when these clumps get dense enough they break into protostars. These protostars continue to collapse under gravity, reducing in volume which in turn increases pressure and temperature to a degree needed for fusion.
once fusion has started an enourmous amount of energy which creates enough outward pressure or radiation pressure to stop the gravitational collapse
Gravity ----> <------ Radiation Pressure
However as a star comes to the end of it life and the radiation pressure decreases the…