They have to be near any iPhone, which will then tell apple where the airtag (which is using Bluetooth) is. It has a CR2032 button cell battery. More recent iPhones can use ultra wideband to more accurately track the airtag position.
Does it only have to be phones (and specifically iPhones) or can it triangulate from wifi, like a ton of other tracking things do? Even if you don't connect to the wifi, the polling for available Wi-Fi connections can still be used to triangulate position.
All the tracker does (to my knowledge) is sending out a Bluetooth signal every Bluetooth-capable device that has been backdoored the appropriate software running and Bluetooth enabled, which is at least all IPhones, as well as many Android smartphones, will pick up. Those devices will calculate the rough distance based on the delay, and then send the rough location to the Apple servers. The Airtag itself does not calculate anything.
Reminds me a bit about how the German covid app worked. Obviously not for location tracking, but to track whether you got in contact with someone who's potentially infected.
Air Tags have a battery and have short-range low-energy communication with phones. What makes them work out-of-range of your phone is that their signal can be picked up by any phone that participates in Apple's tracking network. Say your luggage has an Air Tag in it, and it ended up flying to a different city than you. Your phone obviously can't find the Air Tag because it's out of range, but someone in that other city is bound to have an iPhone. Their phone sees the signal from your Air Tag and reports that location back to Apple's servers. Apple updates the last known location of that tag. You check your phone to see where your luggage is and your phone requests that info from Apple's servers. Apple sends your phone that data, and now you can see your luggage ended up in Timbuktu while you're in Seattle or wherever.