Here's why:
* Metals tend to lose electrons, forming positively charged ions called cations.
* Nonmetals tend to gain electrons, forming negatively charged ions called anions.
The opposite charges of cations and anions attract each other, creating the strong electrostatic forces that hold the ionic compound together.