The fantasia (Italian: [fantaˈziːa]; also English: fantasy, fancy, fantazy, phantasy, German: Fantasie, Phantasie, French: fantaisie) is a musical composition with its roots in the art of improvisation. Because of this, like the impromptu, it seldom approximates the textbook rules of any strict musical form.
The term was first applied to music during the 16th century, at first to refer to the imaginative musical "idea" rather than to a particular compositional genre. Its earliest use as a title was in German keyboard manuscripts from before 1520, and by 1536 is found in printed tablatures from Spain, Italy, Germany, and France. From the outset, the fantasia had the sense of "the play of imaginative invention", particularly in lute or vihuela composers such as Francesco Canova da Milano and Luis de Milán. Its form and style consequently ranges from the freely improvisatory to the strictly contrapuntal, and also encompasses more or less standard sectional forms (Field 2001).
According to the Oxford Dictionary of Music, in the 16th century the instrumental fantasia was a strict imitation of the vocal motet (Kennedy 2006). The English composers William Byrd and John Jenkins both wrote and developed fantasias for viol consort, while Henry Purcell's fantasias are the last 17th century examples of the genre.
From the Baroque period, J. S. Bach's Chromatic Fantasia and Fugue, BWV 903, for harpsichord; Great Fantasia and Fugue in G minor, BWV 542, for organ; and Fantasia and Fugue in C minor, BWV 537, for organ are examples.