Additionally, the electronegativity of the two atoms in a diatomic molecule must be similar in order for a covalent bond to form. Electronegativity is a measure of how strongly an atom attracts electrons. If the electronegativity of the two atoms is too different, then one atom will attract the electrons more strongly than the other, and this will result in an ionic bond.
For example, the diatomic molecule hydrogen chloride (HCl) is held together by a covalent bond because the electronegativity of hydrogen and chlorine is similar. In contrast, the ionic compound sodium chloride (NaCl) is held together by an ionic bond because the electronegativity of sodium and chlorine is very different.