What happens when two magnet come close together?

If they come end-to-end, they will either attract or repel depending on the polarity.

If you bring the sides together, they often will slide to bring their ends + & - ends together.