An electromagnet is a magnet that runs on electricity. Unlike a permanent magnet, the strength of an electromagnet can easily be changed by changing the amount of electric current that flows through it. The poles of an electromagnet can even be reversed by reversing the flow of electricity.
An electromagnet works because an electric current produces a magnetic field. The magnetic field produced by an electric current forms circles around the electric current.