Animated gif depicting a mid-ocean ridge with two oceanic plates moving away from the center of the ridge. As the movement progresses, symettrical magnetic stripes appear on each side of the ridge.

The iron in the solidifying rock preserves the current magnetic polarity as new oceanic plates form at mid ocean ridges

Source: US National Parks Service (https://www.nature.nps.gov/geology/usgsnps/animate/pltecan.html)