Many of the themes and motifs in Twelfth Night derive from the fact that the play was written for the holiday of Twelfth Night, also known as Epiphany Eve. This holiday is a Christian festival that occurs on the last night of the Twelve Days of Christmas. While the holiday has many variations across the globe, in Shakespeare's England, Twelfth Night was a cause for food, drink, and general merriment. Often, this merriment came in the form of absurdity and role-reversals, with people dressing up as their opposite, whether that meant gender or social status.
Though the play is not about the holiday itself, it does operate in the spirit of the Twelfth Night festivities, showing gendered role-reversals through the characters of Viola (who dresses as a man) and Olivia (whose boldness allows her to step into the traditional male role of aggressor). It also makes room for an inverted social hierarchy in the character of Malvolio, a servant who is convinced he can become a nobleman – something that early modern audiences would have recognized as impossible.
There is little composition history about Twelfth Night, so it is unknown whether it was written as a Twelfth Night performance. The earliest known production of the play was on Candlemas in February of 1602, another holiday which Twelfth Night is frequently attached. Regardless of whether the play was written explicitly for the holiday, however, critics have long interpreted its major themes through this historical context, arguing that the play embraces the topsy-turvy spirit of the holiday while providing insightful commentary about early modern gender and society.