The inorganic compound formed between magnesium and sulfur is an ionic compound. The chemical formula MgS represents magnesium sulfide, where magnesium Mg is a metal and sulfur S is a non-metal. In this compound, magnesium loses two electrons to form a +2 cation Mg , while sulfur gains two electrons to form a -2 anion S . The electrostatic attraction between these oppositely charged ions results in the formation of the ionic compound magnesium sulfide.