A Regular Magnet

Before talking about electromagnets, let's talk about normal "permanent" magnets like the ones you have on your refrigerator and that you probably played with as a kid.

You likely know that all magnets have two ends, usually marked "north" and "south," and that magnets attract things made of steel or iron. And you probably know the fundamental law of all magnets: Opposites attract and likes repel. So, if you have two bar magnets with their ends marked "north" and "south," the north end of one magnet will attract the south end of the other. On the other hand, the north end of one magnet will repel the north end of the other (and similarly, south will repel south).

An electromagnet is the same way, except it is "temporary" -- the magnetic field only exists when electric current is flowing.