Which element in lava is responsible for preserving the direction of magnetic field

The element responsible for preserving the direction of the magnetic field in lava is iron. Iron is a magnetic mineral, and when lava solidifies, its iron-rich minerals align with the Earth's magnetic field, preserving the direction of the field at the time of cooling. This phenomenon is known as paleomagnetism and is used by scientists to study the Earth's past magnetic field.