The first stars formed from nebulae that consisted entirely of atoms of the five lightest elements (H until B), which were formed during big bang nucleosynthesis. Atoms of heavier elements, such as carbon (C), oxygen (O), silicon (Si) and iron (Fe), were all formed later during the life cycles of stars in a process known as stellar nucleosynthesis. Through a progressive series of fusion reactions, stars continuously assemble heavier elements out of lighter elements.
The specific elements that may be formed during stellar nucleosynthesis depend on the mass and temperature of the stars. Stars with a low mass, like the Sun, burn slowly and are able to produce elements with an atomic number of up to 6 (C). In comparison, stars with a high mass, for instance 10 – 100 times the mass of the Sun, burn quickly and are able to produce elements with an atomic number of up to 26 (Fe). However, in order to form elements heavier than Fe, even more extreme conditions are required than those that are generally found in very massive stars. The heaviest elements are therefore mostly formed during supernova explosions at the end of a stellar life cycle.
Atoms may either be released into space during the lifetime of stars, or upon their collapse. If atoms move fast enough to overcome the gravitational pull of their stars, they may escape in streams of gas known as stellar winds. Alternatively, they are discharged in large gas clouds and supernovae during the death of stars. In space, atoms may subsequently form new nebulae or may be incorporated into existing nebulae. So, from the remnants of dying stars, successive generations of stars with an increasingly diverse elemental composition are born.
Book reference: Marshak, S. (2007). Earth: Portrait of a Planet: Third International Student Edition. WW Norton & Company.
Image: Galactic center of the Milky Way as seen by the Hubble Space Telescope, Spitzer Space Telescope and Chandra X-ray Observatory. Credit: NASA/JPL-Caltech/ESA/CXC/STScl.