Elements whose atoms have the same number of valence electrons are grouped together in the Periodic Table.
Generally, elements in Groups 1, 2, and 13 to 17 tend to react to form a closed shell with a noble gas electron configuration ending in #ns^2 np^6#.
The most reactive metals are those from Groups 1 and 2.
They need to lose only one or two valence electrons to form positive ions with a noble gas configuration.
Nonmetals tend to attract additional valence electrons to form either ionic or covalent bonds.
The most reactive nonmetals are the halogens, e.g., #"F"# and #"Cl"#.
They have one less electron configuration than a noble gas, so they require only one additional valence electron gain an octet.
To form an ionic bond, a halogen atom can remove an electron from another atom in order to form an anion (e.g., #"F"^"-", "Cl"^"-"#, etc.).
To form a covalent bond, one electron from the halogen and one electron from another atom form a shared pair.
For example, in #"H–F"#, the dash represents a shared pair of valence electrons, one from #"H"# and one from #"F"#.