Elements consist of atoms and these atoms either gain or lose electrons or share them with atoms of other elements, in order to form bonds. There are two common types of bonds: ionic and covalent. An ionic bond is formed between atoms which exchange electrons. That is, some atoms lose electrons, while the other gains them. Covalent bonds are formed between atoms that share electrons.
Among the elements, metals have a tendency to donate or lose electrons. Non-metals have a tendency to gain electrons. When metals and non-metals bind, they form ionic bonds. However, when non-metals react with other non-metals, they have to share electrons, as electrons are not donated by participating atoms.
Thus, among the elements, non-metals share electrons when they form bonds with other non-metals.
Hope this helps.