The molecule H2 consists of two hydrogen atoms bonded together. The bond that holds these two atoms together is a covalent bond. In a covalent bond, atoms share electrons to achieve a full outer shell of electrons, which in the case of hydrogen means sharing a pair of electrons.
In simple terms, each hydrogen atom has one electron. When two hydrogen atoms come together to form H2, they each share their single electron with the other, creating a stable H2 molecule. This type of bonding occurs between nonmetals when they share electrons rather than transferring them, which would create ionic bonds. An ionic bond typically occurs between a metal and a nonmetal, where one atom donates electrons to another. Since H2 involves only hydrogen atoms that share rather than transfer electrons, it is characterized by a covalent bond.