The best way to get magnesium is through your diet and eating a variety of magnesium-rich foods, such as spinach, legumes, nuts, seeds, and whole grains. Supplements are an option for maintaining magnesium levels in people whose magnesium levels remain low despite diet changes. Please discuss taking a magnesium oxide supplement with your healthcare provider before taking.