Magnets have an unseen area around them called a "magnetic field". Magnetic objects inside this unseen field are attracted to the magnet. Magnetic things outside the magnetic field are not attracted to the magnet. This is why a magnet must be close to an object to attract it.