Why do elements share electrons?
The atoms of some elements share electrons because this gives them a full valence shell.
All atoms strive to achieve a full valence shell, just like the noble gases. This is the most stable electron arrangement.
If atoms can’t achieve a full outer shell by transferring electrons, they resort to sharing. In this way, each atom can count the shared electrons as part of its own valence shell. This sharing of electrons is covalent bonding.
For example, an oxygen atom has six electrons in its valence shell. The most the shell can hold is eight. Two oxygen atoms can share their valence electrons as shown below.
Each atom counts the four shared electrons as part of its valence shell. Thus, each atom has eight valence electrons, a stable noble gas configuration.