Electromagnet is an temporary magnet produced when electric current is passed through specific materials.
The process of production of electromagnet is explained as follows :
From Oersted's law, we know that a current carrying conductor produces a magnetic field around it.
The same principle is applied in the production of electromagnet.
A ferromagnetic material is wound by insulated copper wires. The current is allowed to pass through wounded ferromagnetic material which in turn, produces magnetic field around it, and acts just like a strong electromagnet.
The magnetism is retained as long as there is current flow in the wire.