Ionic compounds form when a metal and nonmetal bond, as the metal loses its valence electrons which the nonmetal gains, resulting in an ionic bond. Covalent compounds form when two nonmetals bond, as they tend to share electrons allowing them to complete their valence shells resulting in a covalent bond. ;
Two nonmetals have enough electrons to share some for completing, so the bonds are covalent. A metal doesn't have that much, so it gives the few electrons on its outer layer more easily than a nonmetal (there must be a nonmetal to get them). This bond is ionic. I'm still unaware of possible bonds between 2 metals (are there any? :) )
Ionic compounds form when metals transfer electrons to nonmetals, creating charged ions that attract one another. In contrast, covalent compounds are formed when nonmetals share electrons, allowing both atoms to achieve full outer shells. The type of bond—ionic or covalent—depends on whether the elements involved are metals or nonmetals.
;