Magnesium is obtained from food or from a supplement. Foods high in magnesium include green leafy vegetables, legumes, nuts and seeds and wholegrains.