A covalent bond forms when two atoms share a pair of electrons. The shared pair is attracted to the nuclei of both atoms, and that attraction holds the atoms together. Non-metal atoms join by sharing electrons until each has a full outer shell, and the particles they make are called molecules. Substances made of small molecules are simple molecular substances.
A dot and cross diagram shows only the outer electrons. Electrons from one atom are drawn as dots and electrons from the other atom as crosses, and a shared pair sits where the two outer shells overlap. In hydrogen, H2, each atom brings one electron, so the atoms share one pair and form a single bond. In hydrogen chloride, HCl, hydrogen shares one pair with chlorine. Chlorine has seven outer electrons, so after sharing it has one shared pair and three non-bonding pairs, which gives a full outer shell of eight electrons.
In water, H2O, oxygen has six outer electrons. It forms two single bonds, one with each hydrogen atom, and keeps two non-bonding pairs. In methane, CH4, carbon has four outer electrons and shares them with four hydrogen atoms, forming four single bonds. In oxygen, O2, each atom needs two more electrons, so the atoms share two pairs and are joined by a double bond. In carbon dioxide, CO2, the carbon atom forms two double bonds, one with each oxygen atom.