# How does permanent magnets attract each other if the $B$-field can do no work? [duplicate]

How can two permanent magnets do work on each other?

If you put two magnets with opposite poles facing each other they will attract each other. If you put them with the same poles facing each other they will repel each other.

What is the mechanism behind this? A static $B$-field can do no work, and still the magnets will attract/repel.