A play within a play is a dramatic device where a play is performed on stage by characters in a play, often with other characters forming an "audience". The play within a play often has symbolic and psychological significance, as well as having an important function in the plot.

A play within a play was apparently first used by Thomas Kyd in The Spanish Tragedy around 1587, where it forms the spectacular resolution of the story. Kyd is also assumed to have used it in his lost Hamlet (the so-called Ur-Hamlet). William Shakespeare used this device notably in A Midsummer Night's Dream and his Hamlet.

In Hamlet the fiction of the inner play is used to reveal the truth in the outer play. In The Spanish Tragedy, Hieronimo is so convinced of the far-reaching consequences of his "revelation" that he predicts it will bring about the "fall of Babylon". In his use of the play within the play, Kyd seems to take Aristotle's idea of drama as catharsis to its apocalyptic conclusion.

The device, then, can also be an ironic comment on drama itself, with inversions and reversals of its basic elements: actors become authors, while the audience in the theatre sometimes loses its privileged omniscient position because it is suddenly not clear what the characters on stage are doing.

Alternatively, a play might be about the production of a play, and include the performance of all or part of the play, as in Noises Off or The Producers.

A storyteller might tell a story about a character that tells a story, as in The Book of One Thousand and One Nights.