You can travel on Hungarian motorways and dual carriageways by motorbike, car, bus, with a trailer, or with trucks under 3.5 tonnes only with a valid motorway vignette. The rules do not require you to have a physical sticker on your windshield, so you can pay electronically. Vignettes can be purchased at petrol stations or via this link without a convenience fee.
When to buy it?
Just as you have to buy a ticket in advance for public transport, you also have to buy the sticker before driving onto the motorway. If you forget to buy the sticker, you still have an hour to stop and buy it at a petrol station or online (of course not while driving). You need a sticker not only on motorways but also on dual carriageways.