Nonmetals tend to form bonds primarily B. by gaining electrons.
This is because nonmetals have higher electronegativities and generally have a tendency to acquire electrons to achieve a full valence shell, typically following the octet rule. When nonmetals gain electrons, they typically form anions (negatively charged ions) and can further engage in ionic or covalent bonding with other elements.