Answer:
They were formed right after the "Big Bang" when our known universe originated from pure energy some billions of years ago. The energy was converted to the elementary particles (quarks, gluons, leptons etc...) from which protons and neutrons were formed. From these, atoms of different elements were produced