Magnesium hydroxide is used to treat occasional constipation in children and adults on a short-term basis. Magnesium hydroxide is in a class of medications called saline laxatives. It works by causing water to be retained with the stool. This increases the number of bowel movements and softens the stool so it is easier to pass.