When two non-metals react together, they both need to gain electrons to complete full outer shells. The only way this can be achieved is if they share their outer electrons
Hydrogen: Each hydrogen atom has only one electron and needs one more to complete its first shell. When two hydrogen atoms get close together their shells can overlap and then they can share their electrons.
Since, electrons are being shared, there is a strong force of attraction between them. This force is a covalent bond.
The bonded atoms form molecules. Hydrogen's molecular formula is H2.
Chlorine: A chlorine atom needs a share of one other electron to obtain a full outer shell. If two chlorine atoms are placed together the result is as shown below:
Oxygen: Each oxygen atom requires a share of two electrons.
Since each oxygen atom has a share of two pairs of electrons, we call this a double covalent bond.
There is a vast number of compounds that exist as molecules.
Water: In each molecule, H2O, one oxygen atom shares electrons with two hydrogen atoms.
Ammonia: In each molecule, NH3, one nitrogen atom shares its electrons with three hydrogen atoms, so that they all reach full shells.
Methane: Its formula is CH4. One carbon atom shares its electrons with four hydrogen atoms.