The formation of atoms

The Universe consists mainly of hydrogen and helium atoms. The other elements represent less than 1% of matter. These rare elements are however necessary to form solid matter, the ice and rock which make up terrestrial planets ? .

The relative proportion of the elements today present (figure below) reflects the processes which formed these atoms.

On the figure, note that the scale is logarithmic. There are 3 intervals between H (hydrogen) and O (oxygen), the most abundant atom after hydrogen and helium. This means that there area $10^3=1,000$ times more hydrogen atoms than oxygen atoms.

Relative abundance of elements ? in the Universe according to the number of protons ? in the nucleus.
(Wikipedia)

At the origin of the Universe, only the lightest atoms, hydrogen (H), helium (He), and a little lithium (Li) and beryllium (Be) were formed during the Big Bang. All the other atoms were created subsequently, primarily through thermonuclear reactions within the stars.

The life of the stars comprises several stages, and the creation of each atom is associated with one of them.

The first generation stars, comprising H and He, could not have solid planets. They formed atoms of carbon (C), oxygen (O), nitrogen (N) and fluorine (F). At the end of their life they became novae ?  or supernovae ?  and ejected their matter into the Interstellar Medium ?  (ISM). The second generation stars therefore contained a little C, N, O et F... and their planets could contain water (H2O), carbon monoxide (CO), carbon dioxide (CO2)... Several generations of stars were needed in order to obtain planets with rock and metals.

The Sun, which is 4.5 billion years old, was formed in a medium enriched by several generations of stars (many stars have lifetimes of just a few million years).