Flocculation of microalgae is a promising low-cost strategy to harvest microalgae for bulk biomass production. However, residual flocculants can interfere in further downstream processes or influence biomass quality. In this study, a new concept is demonstrated based on reversible magnesium hydroxide flocculation, using Chlorella vulgaris and Phaeodactylum tricornutum as respectively a freshwater and a marine model species. We show that flocculation was induced by precipitation of magnesium hydroxide at high pH (10 to 10.5). This resulted in a magnesium content of the microalgal biomass of 5% for Chlorella and 18% for Phaeodactylum. After pre-concentration of the microalgal biomass by gravity sedimentation, 95% of the precipitated magnesium hydroxide could be removed from the biomass by mild acidification (pH 7 to 8). The pH fluctuations experienced by the microalgae during flocculation/de-flocculation had no influence on biomass composition (FAME, total N and P, carbohydrates, proteins, mineral content) and on the viability of microalgal cells. Magnesium can thus be used as pH-dependent reversible flocculant for harvesting microalgae in both marine and freshwater medium.