Magnesium oxide (MgO) is an ionic compound. It is composed of magnesium ions (Mg2+) and oxide ions (O2-). The magnesium ions are attracted to the oxide ions by electrostatic forces. This attraction is strong enough to hold the compound together in a crystalline structure.