Trick-or-treating has been associated with Halloween celebrations in the U.S. and Canada since the early 1900s, but, as Statista's Katharina Buchholz notes, traditions of children going door to door in a quest for treats exist in many parts of the world, with one European custom being widely recognized as the precursor of the North American tradition.
You will find more infographics at Statista
As far back as the Middle Ages, people in the British Isles dressed up for holidays and went from door to door performing scenes in order to receive a thank-you in the form of food and drink. The tradition is preserved today in Scotland and Ireland under the name guising and features dressed-up children rather than theater displays. The origin of Halloween, celebrated on October 31, also goes back to Celtic traditions, more specifically the Samhain festival, which marked the beginning of winter and a time when fairies and spirits needed to be appeased. Like many Christian holidays, All Saints' Day (November 1) and its eve, All Hallows' Day, coincide with the pagan festival and trick-or-treating is done in Portugal on the first day of November. All Saints' Day also has a big significance in Mexico (celebrated as Day of the Dead there) but U.S. Halloween traditions have also been adopted, most heavily in the Northern and Central parts of the country, where the custom is named calaverita (litte skull) after the sugar skulls which are gifted for the festival.
But scary dress and trick-or-treating antics are not tied to a single date: Scandinavian children engage in them around Easter, while those in Northern Germany and Southern Denmark pick New Year's Eve. In Southern Germany, Austria Switzerland, the Netherlands and Flanders in Belgium, treats are given out not for threats, but for songs, which children perform on November 11 (St. Martin's Day). Caroling for sweets is also performed during Ramadan in Central Asia. This is where trick-or-treating blends into Christmas caroling, which is sometimes also rewarded with food offerings, for example in Eastern Europe.
The practice is associated most closely with England and the United States, but involves adults as well as children and more commonly the collection of money, for example for charity.