Every electron in atom has a magnetic moment associated with it.
Two types of magnetic moment are there :
1. Orbital Magnetic Moment
2. Spin Magnetic Moment
Magnetic moments of adjacent electrons usually cancel out due to their opposite spins.
But when an emf is applied, electrons flow in the same direction.
The magnetic moments of various electrons get aligned in the same direction.
Thus a strong magnetic field is created.