Halloween has its roots in the ancient, pre-Christian Celtic festival of Samhain, which was celebrated on the night of October 31. The Celts, who lived 2,000 years ago in the area that is now Ireland, the United Kingdom, and northern France, believed that the dead returned to the earth on Samhain (Halloween). On a sacred night, people gathered to light bonfires, offer sacrifices, and pay homage to the dead.
During some Celtic celebrations of Samhain, villagers disguised themselves in costumes made of animal skins to drive away phantom visitors; banquet tables were prepared and food was left out to appease unwelcome spirits.
In later centuries, people began dressing as ghosts, demons, and other malevolent creatures, performing antics in exchange for food and drink. This custom, known as mumming, dates back to the Middle Ages and is thought to be an antecedent of trick-or-treating.
By the 9th century, Christianity had spread into Celtic lands, where it gradually blended with and supplanted older pagan rites. Celebrations in England resembled Celtic commemorations of Samhain, complete with bonfires and masquerades. Poor people would visit the houses of wealthier families and receive pastries called soul cakes in exchange for a promise to pray for the souls of the homeowners' dead relatives. Known as "souling," the practice was later taken up by children, who would go from door to door asking for gifts such as food, money, and ale.
In Scotland and Ireland, young people took part in a tradition called "guising", dressing up in costume and accepting offerings from various households. Rather than pledging to pray for the dead, they would sing a song, recite a poem, tell a joke or perform another sort of "trick" before collecting their treat, which typically consisted of fruit, nuts, or coins.
The earliest known reference to the phrase "trick-or-treat" in North America is from 1927 in Alberta, Canada.