Magnetic attraction and repulsion are demonstrated by bringing two magnets in close contact. When the like poles are near each other, they will attract the two magnets together, and when the different poles are near, they push the magnets away from each other.
To demonstrate the attractive and repulsive forces of magnetism, take two bar magnets and lay them on a flat surface, then bring them slowly together. When the north and south poles are aligned, the magnets will pull on each other and stick together. Now, turn one of the magnets around and repeat the process. The magnets will now repel each other with a force that actually moves the stationary magnet. The same demonstration is also possible by placing one magnet on top of the other. In one configuration, the lower magnet will leap up to join the upper one, while in the opposite arrangement, the repulsive force pushing against the upper magnet can be felt physically. If a bar magnet is broken in half, it will create different poles at each broken end, which repel each other and resist the two halves joining again.
Objects become magnetized when tiny magnetic domains are aligned within their material. Many elements are naturally magnetic, while others have their magnetic domains aligned through chemical or electrical processes. The earth itself is actually one giant magnet, which is why compasses and other magnetic materials align themselves with the poles of the planet.