Unlike magnetic poles attract each other, and like magnetic poles repel each other. Magnets produce a magnetic field that is an area of magnetic force that determines whether the poles are attracted or repulsed.
Magnets are any objects that produce their own magnetic fields that interact with other magnetic fields. A magnet has a north pole and a south pole. The field lines that start at the north pole and end at the south pole represent the magnetic field, which is invisible to the human eye. This magnetic field causes the magnetic force that results in attraction or repulsion when two magnets are next to one another, according to Northeastern University.
Unlike magnetic poles attract
If unlike magnetic poles are facing each other, that is one north pole and one south pole, the magnetic field lines travel from the north pole of one magnet to the south pole of the other. This results in an attractive magnetic force.
Like magnetic poles repel
If like magnetic poles are facing each other, that is two north poles or two south poles, the magnetic field lines travel away from each other, resulting in a repelling force between the magnets. If the magnets are close together, this force pushes them away from one another.