Magnetic fields are produced by the motion of electrical charges. For example, the magnetic field of a bar magnet results from the motion of negatively charged electrons in the magnet. The origin of the Earth's magnetic field is not completely understood, but is thought to be associated with electrical currents produced by the coupling of convective effects and rotation in the spinning liquid metallic outer core of iron and nickel. This mechanism is termed the dynamo effect.
[Shockwave movie of fluid motion in the Earth's core and the dynamo effect? Also show magnetic fields produced by current in a coil of wire? Or include latter in Shockwave of field of a bar magnet?]