Generally speaking, a composition in which the "free flight of fancy" prevails over contemporary conventions of form, style, etc.  Naturally, the term covers a great variety of types, which may be tentatively classified as five groups.

1)  Pieces of a markedly improvisory character; written records, as it were, of the improvisation technique of the various masters.

2)  Character pieces of the romantic era.  Here "fantasia" is one of the various titles used to indicate a dreamlike mood or some other fanciful whim. 3)  Sonatas in freer form, or of a special nature. 4)  Operatic potpourris of a free and somewhat improvisory treatment, as if written in remembrance of a performance 5)  In the 16th and 17th centuries, a term for instrumental music that was sometimes used interchangeably with ricercar.  These were written for the lute, for keyboard instruments, and for instrumental ensembles.