Ionic compounds form when oppositely charged ions attract each other, forming ionic bonds. Ions are formed when atoms gain or lose valence electrons to achieve a stable electron configuration. In ionic compounds, the cation is written first followed by the anion in chemical formulas. Metals form metallic bonds where metal atoms donate their valence electrons, which are free to move throughout the crystal lattice structure.