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.