The transformation that converts 7-dehydrocholesterol to vitamin D occurs in two steps. First, 7-dehydrocholesterol is photolyzed by ultraviolet light in a 6-electron conrotatory ring-opening electrocyclic reaction; the product is previtaminD. Second, previtaminD spontaneously isomerizes to vitaminD (cholecalciferol) in an antarafacial [[Sigmatropic shift#.5B1,7.5D Shifts|sigmatropic [1,7] hydride shift]]. At room temperature, the transformation of previtaminD to vitamin D in an organic solvent takes about 12 days to complete. The conversion of previtaminD to vitamin D in the skin is about 10 times faster than in an organic solvent.
The conversion from ergosterol to vitamin D follows a similar procedure, forming previtaminD by photolysis, which isomerizes to vitamin D (ergocalciferol). The transformation of previtaminD to vitamin D in methanol has a rate comparable to that of previtaminD. The process is faster in white button mushrooms.