Yes, magnets work in a vacuum just as well as they do in air.
The magnetic force is a fundamental force of nature that, unlike some other physical phenomena, does not require a medium (like air or water) to propagate. Magnets attract or repel each other through what is known as a "field," specifically a magnetic field. This field exists regardless of the presence of air or any other matter.
Why Magnets Work in a Vacuum:
- Magnetic fields are fundamental: Magnetic fields are a property of space itself. They are generated by moving electric charges (like electrons within the magnet) and exist independently of any surrounding material.
- "Action at a distance": Magnetism is an example of "action at a distance," meaning that the force can be exerted across empty space. No physical connection or medium is needed to transmit the force. Think of gravity as another example; the Earth's gravity pulls on the Moon even though there's a vacuum between them.
Analogy:
Imagine waving your hand. You're disturbing the air, creating a wave that someone nearby can feel. That's like a sound wave that requires air. Now imagine radiating heat from a fire. You can feel the heat even if you are far away, with no air in between you and the fire. The heat comes from infrared electromagnetic waves that radiate in a vacuum. Magnets and magnetic fields are more like the heat radiating from a fire.
In Summary:
Because the magnetic force is mediated by a magnetic field, which is a fundamental property of space and does not require a medium to propagate, magnets function perfectly well in a vacuum.