A star goes through a life cycle, and the path it follows depends on its size. Every star begins as a nebula, which collapses under gravity to form a protostar. When fusion starts, the protostar becomes a main sequence star. This is the long, stable part of a star's life, where hydrogen nuclei fuse to make helium.
A star about the size of the Sun swells into a red giant when its hydrogen runs low. It then shrinks to a hot, dense white dwarf, which cools and fades.
A star much more massive than the Sun swells into a red supergiant, then explodes as a supernova. The core left behind becomes either a neutron star or a black hole.
Fusion in stars joins smaller nuclei to make larger nuclei, so new elements form. Fusion produces all the naturally occurring elements up to iron. Elements heavier than iron are produced in a supernova, and the explosion spreads the elements through the universe.