A libretto is the text (the words) which are set to music to make an opera. A libretto can also be the words for an oratorio, cantata, mass or a musical. The person who writes the libretto is called a librettist. The word “libretto” (plural: “libretti” or “librettos”) is an Italian word which means “little book”.
Sometimes a composer writes his own libretti, but usually a composer likes to have a librettist who can write the words for him so that he can set them to music.
Some libretti are original stories by the librettist, but very often they are based on a book by another writer.
In the 18th century Metastasio was a very famous librettist. Many of his libretti were set several times by different composers. Another 18th century librettist was Lorenzo da Ponte, who wrote the libretti for three of Mozart's greatest operas, as well as for many other composers. In the 19th century Eugène Scribe wrote a very large number of libretti that were set to music by composers such as Meyerbeer, Auber, Bellini, Donizetti, Rossini and Verdi. Two French writers called Henri Meilhac and Ludovic Halévy wrote a large number of opera and operetta libretti for the composers Jacques Offenbach, Jules Massenet and Georges Bizet. Arrigo Boito, who wrote libretti for, among others, Giuseppe Verdi and Amilcare Ponchielli, composed two operas of his own. Hugo von Hoffmansthal wrote libretti for Richard Strauss.
Usually a libretto is written before the music, but sometimes composers wrote some of the music first and then looked for words to go with it. Composers, such as Mikhail Glinka, Alexander Serov, Rimsky-Korsakov, Puccini, and Mascagni all did this sometimes.
Musicals usually have lyrics (the words for the songs), and a separate "book" ( the spoken dialogue and the stage directions). Sometimes these two are by different authors, e.g. the musical Fiddler on the Roof has a composer (Jerry Bock), a lyricist (Sheldon Harnick), and the writer of the "book" (Joseph Stein).