The modern tradition of passing out candy to trick-or-treaters on Halloween is likely based on the medieval custom of "souling" on All Souls' Day. Early Christians made currant-topped desserts called "soul cakes" to honor their dead on All Souls' Day, and children would walk from house to house singing for the cakes. The children agreed to pray for the dead relatives of each person that gave them a soul cake.
Combining rituals of Roman Catholicism, Celtic harvest festivals and paganism, the modern Halloween is a celebration of both secular and religious traditions. Trick-or-treating became popular in the United States in the 1940s.
The custom of dressing up in costume can be attributed to the more recent Scottish and Irish practice of "guising." In the late-19th century celebrations of Halloween in Europe, Scottish and Irish children would go door-to-door wearing disguises and perform a song or tell a joke for food or money. Scottish and Irish immigrants then brought this tradition to North America.
The phrase "trick-or-treat" as used to playfully threaten vandalism on Halloween is thought to have been first used in Canada in 1927. In certain parts of Mexico, children participate in a similar tradition. Children travel from door to door saying calaverita, which means "little skull" and has the same effect as saying "trick or treat."