Samuel Taylor Coleridge subtitled "Kubla Khan" as "A Vision in a Dream: A Fragment." In his prefatory note, he describes the circumstances under which he composed it. He had been reading about Kubla Khan in Purchas His Pilgrimage when he fell asleep in his chair. During his three-hour nap, "images rose up before him as things, with a parallel production of the correspondent expressions, without any consciousness of effort."
Although this happened nearly a century before the invention of movies, this description sounds surprisingly like a film. However, Coleridge's "movie" was subtitled with elegant poetry, about three hundred lines in all. When Coleridge woke up, he remembered the whole thing and began furiously recording what he'd dreamt. Unfortunately, he was "called out by a person on business from Porlock," and by the time he could extract himself from the caller, the words had vanished.
Considering the beauty and technical brilliance of the fragment Coleridge recorded, his story seems far-fetched. Could someone dream a poem of that caliber? Many commentators have made much of the fact that Coleridge's dream was opium-induced. He had taken "two grains of opium" for an intestinal complaint before his nap. Since some poets and musicians believed that laudanum aided their creativity, perhaps the drug can be credited with the dream and the poem.
However, one need not resort to the explanation of opium as the sole cause of this poetic dream. In 1797, when Coleridge wrote "Kubla Khan," he had begun spending a significant amount of time with William and Dorothy Wordsworth. The three poets collaborated for hours each day on their poetry, advising each other and contributing to each other's verses. For both William Wordsworth and Coleridge, it was an especially productive time in their writing careers.
When a person becomes fluent in a foreign language, they begin to dream in that language. In the same way, Coleridge's extended exposure to the rhythm, rhyme, and meter of poetry no doubt influenced his dreams. The poem is written in a strong iambic rhythm with an irregular rhyme scheme. Since Coleridge was spending such a large portion of his waking hours working in iambic rhythm and rhyme, his brain could "write poetry in his sleep," which is what it apparently did with "Kubla Khan."
"Kubla Khan" is considered one of Coleridge's most beautiful and impressive lyrics. Opium alone could not have produced such a masterpiece; Coleridge's talent for language and his immersion in his craft spilled over into his dream to produce this beloved piece.