The play is believed to have drawn extensively on the Italian production Gl'ingannati (or The Deceived Ones), collectively written by the Accademia degli Intronati in 1531. It is conjectured that the name of its male lead, Orsino, was suggested by Virginio Orsini, Duke of Bracciano, an Italian nobleman who visited London in the winter of 1600 to 1601.
The actual Elizabethan festival of Twelfth Night would involve the antics of a Lord of Misrule, who before leaving his temporary position of authority, would call for entertainment, songs and mummery; the play has been regarded as preserving this festive and traditional atmosphere of licensed disorder. This leads to the general inversion of the order of things, most notably gender roles. The embittered and isolated Malvolio can be regarded as an adversary of festive enjoyment and community, led by Sir Toby Belch, "the vice-regent spokesman for cakes and ale" and his partner in a comic stock duo, the simple and constantly exploited Sir Andrew Aguecheek.
Viola is not alone among Shakespeare's cross-dressing heroines; in Shakespeare's theatre, convention dictated that adolescent boys play the roles of female characters, creating humour in the multiplicity of disguise found in a female character who for a while pretended at masculinity. Her cross dressing enables Viola to fulfill usually male roles, such as acting as a messenger between Orsino and Olivia, as well as being Orsino's confidant. She does not, however, use her disguise to enable her to intervene directly in the plot (unlike other Shakespearean heroines such as Rosalind in As You Like It and Portia in The Merchant of Venice), remaining someone who allows "Time" to untangle the plot. Viola's persistence in transvestism through her betrothal in the final scene of the play often engenders a discussion of the possibly homoerotic relationship between Viola and Orsino. Her impassioned speech to Orsino, in which she describes an imaginary sister who "sat like patience on a monument, / Smiling at grief" for her love, likewise causes many critics to consider Viola's attitude of suffering in her love as a sign of the perceived weakness of the feminine (2.4).
At Olivia's first meeting with "Cesario" (Viola) in I.V she asks her "Are you a comedian?" (an Elizabethan term for "actor"). Viola's reply, "I am not that I play", epitomising her adoption of the role of Cesario, is regarded as one of several references to theatricality and "playing" within the play. The plot against Malvolio revolves around these ideas, and Fabian remarks in Act III, Scene iv: "If this were play'd upon a stage now, I could condemn it as an improbable fiction". In Act IV, Scene ii, Feste (The Fool) plays both parts in the "play" for Malvolio's benefit, alternating between adopting the voice of the local curate, Sir Topas, and his own voice. He finishes by likening himself to "the old Vice" of English Morality plays. Other influences of the English folk tradition can be seen in Feste's songs and dialogue, such as his final song in Act V. The last line of this song, "And we'll strive to please you every day", is a direct echo of similar lines from several English folk plays.