They are mostly magnetic. The ones on clothing are two piece and a pin is inserted through an inconspicuous part of the clothing and attached to a back plate.
Ones on bottles can be placed over the neck or corded to a disc.
There are also flat tags that attach to smaller items. These are either rubbed over a magnetic pad near the till or bent to break the connection inside.
NOTHING will stop the alarm going off if you exit the shop.
At the store where i work they've tried foil, those new foil lined cool bags all to no avail.
Mind you we do have thieves that come in armed with wire cutters to get the cable off bottles, take the item out of the packaging or bring in an accomplice. The accomplice picks up an item with the excuse that they want to see the clothing in daylight triggering the alarm. The other one then pushes through.
It costs retailers millions every year and this cost goes on your shopping.
As an example the supermarket I work in recently had a stock take and was just over £30k short. That's at a store that's reasonable in size (not a co-op or local shop but a smaller version of a big 4) . Just imagine what a superstore supermarket looses every year!