Elements of the supernatural and the fantastic were an element of literature from its beginning. The modern genre is distinguished from tales and folklore which contain fantastic elements, first by the acknowledged fictitious nature of the work, and second by the naming of an author. Works in which the marvels were not necessarily believed, or only half-believed, such as the European romances of chivalry and the tales of the Arabian Nights, slowly evolved into works with such traits. Authors like George MacDonald (1824 –1905) created the first explicitly fantastic works.
Later, in the twentieth century, the publication of The Lord of the Rings by J. R. R. Tolkien enormously influenced fantasy writing, establishing the form of epic fantasy. This also did much to establish the genre of fantasy as commercially distinct and viable. And today fantasy continues as an expansive, multi-layered milieu encompassing many subgenres, including traditional high fantasy, sword and sorcery, magical realism, fairytale fantasy, and horror-tinged dark fantasy.
Even the most fantastic myths, legends and fairy tales differ from modern fantasy genre in three respects:
Modern genre fantasy postulates a different reality, either a fantasy world separated from ours, or a hidden fantasy side of our own world. In addition, the rules, geography, history, etc. of this world tend to be defined, even if they are not described outright. Traditional fantastic tales take place in our world, often in the past or in far off, unknown places. It seldom describes the place or the time with any precision, often saying simply that it happened "long ago and far away." (A modern, rationalized analog to these stories can be found in the Lost World tales of the 19th and 20th centuries.)
The second difference is that the supernatural in fantasy is by design fictitious. In traditional tales the degree to which the author considered the supernatural to be real can span the spectrum from legends taken as reality to myths understood as describing in understandable terms more complicated reality, to late, intentionally-fictitious literary works.
Finally, the fantastic worlds of modern fantasy are created by an author or group of authors, often using traditional elements, but usually in a novel arrangement and with an individual interpretation. Traditional tales with fantasy elements used familiar myths and folklore, and any differences from tradition were considered variations on a theme; the traditional tales were never intended to be separate from the local supernatural folklore. Transitions between the traditional and modern modes of fantastic literature are evident in early Gothic novels, the ghost stories in vogue in the 19th century, and Romantic novels, all of which used extensively traditional fantastic motifs, but subjected them to authors' concepts.
By one standard, no work created before the fantasy genre was defined can be considered to belong to it, no matter how many fantastic elements it includes. By another, the genre includes the whole range of fantastic literature, both the modern genre and its traditional antecedents, as many elements which were treated as true (or at least not obviously untrue) by earlier authors are wholly fictitious and fantastic for modern readers. But even by the more limited definition a full examination of the history of the fantastic in literature is necessary to show the origins of the modern genre. Traditional works contain significant elements which modern fantasy authors have drawn upon extensively for inspiration in their own works.
With increases in learning in the medieval European era, literary fiction joined earlier myths and legends. Among the first genres to appear was romance. This genre embraced fantasy, and not only simply followed traditional myths and fables, but, in its final form, added new fantastical elements. Romance at first dealt with traditional themes, above all three thematic cycles of tales, assembled in imagination at a late date as the Matter of Rome (focusing on military heroes like Alexander the Great and Julius Caesar), the Matter of France (Charlemagne and Roland, his principal paladin) and the Matter of Britain (the lives and deeds of King Arthur and the Knights of the Round Table, within which was incorporated the quest for the Holy Grail), although a number of "non-cyclical" romances also achieved a great deal of popularity.
The romances themselves were fictional, but such tales as Valentine and Orson, Guillaume de Palerme, and Queste del Saint Graal were only the beginning of the fantasy genre, combining realism and fantasy.
During the Renaissance, romance continued to be popular. The trend was to more fantastic fiction. The English Le Morte d'Arthur by Sir Thomas Malory (c.1408–1471), was written in prose; this work dominates the Arthurian literature, often being regarded as the canonical form of the legend. Arthurian motifs have appeared steadily in literature from its publication, though the works have been a mix of fantasy and non-fantasy works. At the time, it and the Spanish Amadis de Gaula (1508), (also prose) spawned many imitators, and the genre was popularly well-received, producing such masterpiece of Renaissance poetry as Ludovico Ariosto's Orlando furioso and Torquato Tasso's Gerusalemme Liberata. Ariosto's tale, with its endlessly wandering characters, many marvels, and adventures, was a source text for many fantasies of adventure. With such works as Amadis of Gaul and Palmerin of England, the genre of fantasy was clearly inaugurated, as the marvels are deployed to amaze and surprise readers.
One English romance is The Faerie Queene of Edmund Spenser. The poem is deeply allegorical and allusive. Leaving allegory aside, however, the action is that of a typical knightly romance, involving knightly duels, and combats against giants and sorcerers. That is probably the first work in which most of the characters are not men, but elves (although the difference seems to be rather little). There are mentioned also the wars between goblins and elf, which were destined to have a great future in fantastic fiction.
The tale of Don Quixote deeply satirized the conventions of the romance, and helped bring about the end of this time of romance, although assisted by other historical trends in fiction. Nevertheless, large subgenres of the field of fantasy have sprung from the romance genre, either directly or through their imitation by latter fantasy writer William Morris.
Literary fairy tales, such as were written by Charles Perrault (1628 – 1703), and Madame d'Aulnoy (c.1650 – 1705), became very popular, early in the Age of Enlightenment. Many of Perrault's tales became fairy tale staples, and influenced latter fantasy as such. Indeed, when Madame d'Aulnoy termed her works contes de fée (fairy tales), she invented the term that is now generally used for the genre, thus distinguishing such tales from those involving no marvels. This would influence later writers, who took up the folk fairy tales in the same manner, in the Romantic era.
Several fantasies aimed at an adult readership were also published in 18th century France, including Voltaire's "contes philosophique" "The Princess of Babylon" (1768) and "The White Bull" (1774), and Jacques Cazotte's Faustian novel The Devil in Love.
This era, however, was notably hostile to fantasy. Writers of the new types of fiction such as Defoe, Richardson, and Fielding were realistic in style, and many early realistic works were critical of fantastical elements in fiction. Aside from a few tales of witchcraft and ghost stories, very little fantasy was written during this time. Even children's literature saw little fantasy; it aimed at edifying and deplored fairy tales as lies.
In one respect, this was an essential stage in the development of fantasy as a genre. The development of a realistic genre ensured that fantasy could be defined as a distinct type, in contrast.
In reaction to Enlightenment's cult of Reason, Romanticism highly prized the supernatural, tradition and imagination, together with the age in which they were supposed to rule - Middle Ages. These traits readily borrowed traditional elements of the fantastic. The Romantics invoked the medieval romance as justification for the works they wanted to produce, in distinction from the realistic pressure of the Enlightenment; these were not always fantastic, sometimes being merely unlikely to happen, but the justification was used even from fantasy.
One of the first literary results of this fascinations was Gothic novel, a literary genre that began in Britain with The Castle of Otranto (1764) by Horace Walpole. It is the predecessor to both modern fantasy and modern horror fiction and, above all, has led to the common definition of "gothic" as being connected to the dark and horrific. Prominent features of gothic novels included terror, mystery, the supernatural, ghosts, haunted buildings, castles, trapdoors, doom, death, decay, madness, hereditary curses, and so on. The fantastic, dream-like atmosphere pervaded the genre at this point. Gothic tales permitted, but did not require, an element of the supernatural. Some stories appeared to contain such elements and then explained them away. The genre straddled the border between fantasy and non-fantasy, but many elements from it, particularly the houses of particular import, being ancient, owned by nobles, and often endowed with legends, were incorporated in modern fantasy.
Of particular importance to the development of the genre was that the Gothic writers used novelistic techniques and love, such as Defoe was using, rather than the literary style of the romance, and also began to use the landscape for purposes of expressing the characters' moods.
On the other hand, the Gothic still held back the pure fantasy. In The Castle of Otranto, Walpole presented the work as a translation; the fictitious original author is therefore responsible for its fantasical elements, which Walpole distances himself from. One noted Gothic novel which also contains a large amount of fantasy elements (derived from the "Arabian Nights") is Vathek by William Thomas Beckford.
The Romantic interest in medievalism also resulted in a revival of interest in the literary fairy tale. The tradition begun with Giovanni Francesco Straparola and Giambattista Basile and developed by the Charles Perrault and the French précieuses, was taken up by the German Romantic movement. Friedrich de la Motte Fouqué created medieval-set stories such as Undine (1811) and Sintram and his Companions (1815) which would later inspire British writers such as MacDonald and Morris. E. T. A. Hoffmann's tales, such as "The Golden Pot" (1814) and "The Nutcracker and the Mouse King" (1816) were notable additions to the canon of German fantasy.  Ludwig Tieck's collection Phantasus (1812-1817) contained several short fairy tales, including "The Elves".
In France, the main writers of Romantic-era fantasy were Charles Nodier, with Smarra (1821) and Trilby (1822)  and Théophile Gautier in stories such as "Omphale" (1834) and "One of Cleopatra's Nights" (1838), and the later novel Spirite (1866).
In Britain, Sara Coleridge also wrote a fantasy novel, Phantasmion (1837), described as ""the first fairytale novel written in English".
The modern fantasy genre first took root during the 18th century with the increased popularity of fictional travelers' tales, influencing and being influenced by other early forms of speculative fiction along the way, finally unfurling in the 19th century from a literary tapestry of fantastic stories and gaining recognition as a distinct genre (mainly due to the nigh-ubiquitous recession of fantastic elements from "mainstream" fiction) in the late 19th century.
In the early Victorian era, stories continued to be told using fantastic elements, less believed in. Charles Dickens wrote A Christmas Carol, using novelistic characterization to make his ghost story plausible; Scrooge at first doubts the reality of the ghosts, suspecting them his own imagination, an explanation that is never conclusively refuted.
The fairy-tale tradition continued in the hands of such authors as William Makepeace Thackeray, but The Rose and the Ring showed many elements of parody. Hans Christian Andersen, however, initiated a new style of fairy tales, original tales told in seriousness. From this origin, John Ruskin wrote The King of the Golden River, a fairy tale that uses new levels of characterization, creating in the South-West Wind an irascible but kindly character similar to the later Gandalf.
In the late 19th and early 20th centuries, modern fantasy began to take shape. The history of modern fantasy literature begins with George MacDonald, the Scottish author of such novels as The Princess and the Goblin and Phantastes the latter of which is widely considered to be the first fantasy novel ever written for adults. MacDonald also wrote one of the first critical essays about the fantasy genre, "The Fantastic Imagination", in his book A Dish of Orts (1893). MacDonald was a major influence on both J. R. R. Tolkien and C. S. Lewis.
The other major fantasy author of this era was William Morris, a socialist, an admirer of Middle Ages, a reviver of British handcrafts and a poet, who wrote several fantastic romances and novels in the latter part of the century, of which the most famous was The Well at the World's End. He was deeply inspired by the medieval romances and sagas; his style was deliberately archaic, based on medieval romances. In many respects, Morris was an important milestone in the history of fantasy, because, while other writers wrote of foreign lands, or of dream worlds, Morris's works were the first to be set in an entirely invented world: a fantasy world.
These fantasy worlds were part of a general trend. This era began a general trend toward more self-consistent and substantive fantasy worlds. Earlier works often feature a solitary individual whose adventures in the fantasy world are of personal significance, and where the world clearly exists to give scope to these adventures, and later works more often feature characters in a social web, where their actions are to save the world and those in it from peril. In Phantastes, for instance, George MacDonald has a mentor-figure explain to the hero that the moral laws are the same in the world he is about to enter as in the world he came from; this lends weight and importance to his actions in this world, however fantastical it is.
Authors such as Edgar Allan Poe and Oscar Wilde (in The Picture of Dorian Gray) also developed fantasy, in the telling of horror tales, a separate branch of fantasy that was to have great influence on H. P. Lovecraft and other writers of dark fantasy. Wilde also wrote a large number of children's fantasies, collected in The Happy Prince and Other Stories (1888) and A House of Pomegranates (1891).
Despite MacDonald's future influence, and Morris' popularity at the time, it was not until around the start of the 20th century that fantasy fiction began to reach a large audience, with authors such as Lord Dunsany who, following Morris's example, wrote fantasy novels, but also in the short story form. He was particularly noted for his vivid and evocative style. His style greatly influenced many writers, not always happily; Ursula K. Le Guin, in her essay on style in fantasy "From Elfland to Poughkeepsie", wryly referred to Lord Dunsany as the "First Terrible Fate that Awaiteth Unwary Beginners in Fantasy", alluding to young writers attempting to write in Lord Dunsany's style. S. T. Joshi claims that "Dunsany's work had the effect of segregating fantasy—a mode whereby the author creates his own realm of pure imagination—from supernatural horror. From the foundations he established came the later work of E. R. Eddison, Mervyn Peake, and J. R. R. Tolkien.
According to historian Michael Saler, speculative fiction entered a new stage in the 1880s and 1890s as a consequence of the rise of the secular society, where the imagination in literature was freed from the influence of the church. This allowed writers to combine aesthetic literature with the freedom of the New Romance literature and the techniques used in literary realism.
H. Rider Haggard developed the conventions of the Lost World subgenre, which sometime included fantasy works as in Haggard's own She. With Africa still largely unknown to European writers, it offered scope to this type. Other writers, including Edgar Rice Burroughs and Abraham Merritt, built on the convention.
Several classic children's fantasies such as Lewis Carroll's Alice in Wonderland, J. M. Barrie's Peter Pan, L. Frank Baum's The Wonderful Wizard of Oz, as well as the work of E. Nesbit and Frank R. Stockton were also published around this time. Indeed, C. S. Lewis noted that in the earlier part of the 20th century, fantasy was more accepted in juvenile literature, and therefore a writer interested in fantasy often wrote in it to find an audience, despite concepts that could form an adult work.
At this time, the terminology for the genre was not settled. Many fantasies were termed fairy tales, including Max Beerbohm's The Happy Hypocrite and MacDonald's Phantastes. It was not until 1923 that the term "fantasist" was used to describe a writer (in this case, Oscar Wilde) who wrote fantasy fiction. The name "fantasy" was not developed until later; as late as J.R.R. Tolkien's The Hobbit, the term "fairy tale" was still being used.
An important factor in the development of the fantasy genre was the arrival of magazines devoted to fantasy fiction. The first such publication was the German magazine Der Orchideengarten which ran from 1919 to 1921. In 1923, the first English-language fantasy fiction magazine, Weird Tales, was created. Many other similar magazines eventually followed, most noticeably Unknown (AKA Unknown Worlds) and The Magazine of Fantasy & Science Fiction  The pulp magazine format was at the height of its popularity at this time and was instrumental in bringing fantasy fiction to a wide audience in both the U.S. and Britain. Such magazines also played a large role in the rise of science fiction and it was at this time the two genres began to be associated with each other.
Several of the genre's most prominent authors began their careers in these magazines including Clark Ashton Smith, Fritz Leiber, and Ray Bradbury. The early works of many sword and sorcery authors such as Robert E. Howard also began at this time. By 1950, sword and sorcery had begun to find a wide audience, with the success of Howard's Conan the Barbarian, and Fritz Leiber's Fafhrd and the Gray Mouser stories. Howard's works, especially Conan, were to have a noteworthy, even defining, influence on the sword and sorcery subgenre. They were tales of vivid, larger-than-life action and adventure, and after the work of Tolkien, the most widely read works of fantasy. Leiber's stories were particularly noted for their uncommon realism for the time; Unknown developed this trait, with many stories in it showing credibility and realism. Like Morris and Eddison before him, Leiber continued the tradition of drawing on Northern European legend and folklore. C. L. Moore was among Howard's first imitators, with "The Black God's Kiss", in which she introduced Jirel of Joiry and the heroine protagonist to sword and sorcery. According to Gary Lachman, Helena Blavatsky had a significant influence on some of the biggest names in both fantasy and science fiction of the pulp era.
Outside the pulp magazines, several American writers used the medium of fantasy for humorous and satirical purposes, including James Branch Cabell (whose 1919 novel Jurgen became the subject of an unsuccessful prosecution for obscenity), Thorne Smith, with Topper (1926) and Turnabout (1931), and Charles G. Finney, author of The Circus of Dr. Lao (1935).
In Britain in the aftermath of World War I, a notably large number of fantasy books aimed at an adult readership were published, including Living Alone by Stella Benson, A Voyage to Arcturus by David Lindsay, Lady into Fox by David Garnett, Lud-in-the-Mist by Hope Mirrlees, and Lolly Willowes by Sylvia Townsend Warner. E. R. Eddison, another influential writer, wrote during this era. He drew inspiration from Northern sagas, as Morris did, but his prose style was modeled more on Tudor and Elizabethan English, and his stories were filled with vigorous characters in glorious adventures. Eddison's most famous work is The Worm Ouroboros, a long heroic fantasy set on an imaginary version of the planet Mercury. His characters were often of great ability and noble, if not royal, birth. These characters have been admired for his work in making his villains, particularly, more vivid characters than Tolkien's. Others have observed that while it is popular to depict the great of the world trampling on the lower classes, his characters often treat their subjects with arrogance and insolence, and this is depicted as part of their greatness. Indeed, at the end of The Worm Ouroboros, the heroes, finding peace dull, pray for and get the revival of their enemies, so that they may go and fight them again, regardless of the casualties that such a war would have. Several of these writers (including Eddison, Lindsay, and Mirrlees) had their fantasy work republished during the 1960s and 1970s.
In 1938, with the publication of The Sword in the Stone, T. H. White introduced one of the most notable works of comic fantasy. This strain continued with such writers as L. Sprague de Camp.
Literary critics of the era began to take an interest in "fantasy" as a genre of writing, and also to argue that it was a genre worthy of serious consideration. Herbert Read devoted a chapter of his book English Prose Style (1928) to discussing "Fantasy" as an aspect of literature, arguing it was unjustly considered suitable only for children: "The Western World does not seem to have conceived the necessity of Fairy Tales for Grown-Ups". Edward Wagenknecht also discussed fantasy elements in both children's and adult fiction in his 1946 article "The Little Prince Rides the White Deer".
It was the advent of high fantasy, in particular J. R. R. Tolkien's The Hobbit and The Lord of the Rings, which finally allowed fantasy to truly enter into the mainstream. Tolkien had published The Hobbit in 1937 and The Lord of the Rings in the 1950s; while the first was a fairy tale fantasy, the second was an epic fantasy that expanded upon the groundwork of the hobbit. Although Tolkien's works had been successful in Britain, it was not until the late 1960s that they finally became popular in America thanks to its burgeoning counterculture. In the early 60s there was a renewed interest in sword and sorcery, and publishers mined the pulps for older stories to reprint along with the limited amount of new material. In demand for more, Ace Books science fiction editor Donald A. Wollheim felt Tolkien's three part novel had enough elements in common with sword and sorcery that it would appeal to the readers of the latter, after which he published an unauthorized paperback edition. On its first-page blurb, it was described as "a book of sword-and-sorcery that anyone can read with delight and pleasure". But the readers of the book would extend way beyond sword and sorcery fandom. By the end of 1968, The Lord of the Rings had sold over 3 million copies in America. Its unexpected success caused American publishers to swiftly reissue a large number of older, often obscure, fantasy novels, catapulting them to belated success.
It is difficult to overstate the impact that The Lord of the Rings had on the fantasy genre; in some respects, it swamped all the works of fantasy that had been written before it, and it unquestionably created "fantasy" as a marketing category. It created an enormous number of Tolkienesque works, using the themes found in The Lord of the Rings.
Tolkien's works also helped fantasy literature to achieve a new degree of mainstream critical acclaim. Numerous polls to identify the greatest book of the century found The Lord of the Rings selected by widely different groups.
While constructing original fantasy worlds with detailed histories, geographies and political landscapes had been a part of the genre from the time of L. Frank Baum, Tolkien's influence greatly popularized the notion. This led to a subsequent decline of such devices as dream frames to explain away the fantastical nature of the setting. This stemmed not only from his example, but from his literary criticism; his "On Fairy Stories", in which he termed such settings "secondary worlds," was a formative work of fantasy criticism.
The impact that his books, combined with the success of several other series such as C. S. Lewis's Chronicles of Narnia, Mervyn Peake's Gormenghast series and Ursula K. Le Guin's Earthsea, helped cement the genre's popularity and gave birth to the current wave of fantasy literature.
With the immense success of Tolkien's works, publishers began to search for a new series with similar mass-market appeal. Fantasy novels began to replace fiction magazines as the heart of the genre.
Lin Carter edited the Ballantine Adult Fantasy series, when Ballantine pursued the fantasy market; it was so titled to avert its being filed as children's literature. The line contained mostly reprints, but introduced some new fantasy works. Reprinted authors included William Morris, Lord Dunsany, and George MacDonald; more recent authors included Hope Mirrlees's Lud-in-the-Mist, Ernest Bramah's Kai Lung books, and Evangeline Walton's The Island of the Mighty, the success of which led to the publication of the other three novels she had written in that series, and to a distinct strain of Celtic fantasy in later fantasy. Another work in this series that was influential for the Celtic fantasy subgenre was Katherine Kurtz's Deryni Rising.
Although many fantasy novels of this time proved popular, it was not until 1977's The Sword of Shannara that publishers found the sort of breakthrough success they had hoped for. The book became the first fantasy novel to appear on, and eventually top the New York Times bestseller list. As a result, the genre saw a boom in the number of titles published. Fantasy novels of the late 1970s and 1980s included Stephen R. Donaldson's Lord Foul's Bane (1977) the first in The Chronicles of Thomas Covenant, the Unbeliever series, John Crowley's Little, Big (1981), Raymond E. Feist's Magician (1982), Robert Holdstock's Mythago Wood (1984) and Glen Cook's Black Company series.
By the early 1980s the fantasy market was much larger than that of almost all science fiction authors. The long-running series of light fantasies by Piers Anthony (Xanth) and Terry Pratchett (Discworld) regularly hit the bestseller lists from the 1980s onward. Notable books of the 1990s include Robert Jordan's popular series Wheel of Time, Tad Williams' Memory, Sorrow and Thorn series and George R. R. Martin's A Song of Ice and Fire (the basis of the American fantasy drama television series Game of Thrones). A Song of Ice and Fire is considered a path-breaking work which paved the way for a new kind of fantasy referred to as grimdark, which was less idealistic and more violent in nature. With J.K. Rowling's Harry Potter novels, which have become the best selling book series of all time, fantasy is becoming increasingly intertwined with mainstream fiction; a process aided by the international popularity of other works such as Christopher Paolini's Inheritance Cycle, Ranger's Apprentice by John Flanagan, Brandon Sanderson's Stormlight Archive, and Philip Pullman's His Dark Materials. The success of major film adaptations such as The Lord of the Rings, Harry Potter, and The Chronicles of Narnia film series has helped further this trend.
Since the 1990s, the genre has been marked by the rise of female-centric urban fantasy, very different from Tolkien's works, as shown by the popularity of Laurell K. Hamilton's Anita Blake novels and Charlaine Harris' The Southern Vampire Mysteries books.