Frazier Piano Studio

Getting Started With Lilypond

Published by Ryan Frazier
Lilypond logo

Lilypond is an excellent alternative to music notation software like Sibelius and Finale. This tutorial will give you everything you need to know to get started writing music in Lilypond.

Lilypond is radically different in it’s approach. It reads a text file to produce a score instead of utilizing a point and click application. Lilypond gives you a lot of power to customize your music scores.

We will be using LilyBin for this tutorial. There is nothing to download and install. You can run all the examples in your browser.

As a side note, every music snippet found on this blog is produced using the Lilypond files found on my Github account.

Pros and Cons of Lilypond


  • It’s free
  • It’s pretty
  • Music described in a text file – no special file formats that no other program can read
  • The score is highly customizable
  • You can even make amazing Shenker graphs
  • It has good editors like Frescobaldi (which I use) or others like LilyBin or Demeno
  • Midi keyboard input support in Frescobaldi and Demeno
  • Beautiful extra fonts at Music Type Foundry
  • Music can be versioned (with git, for example)
  • You can script it and build your own tools (as I have done to build this blog)


  • A learning curve
  • May have to use the command line to get more control of output (like producing svg snippets I use for this blog)
  • Might be hard to figure out why the score won’t render
  • Hard to get your score exactly how you want (which is true of any program)

Although a little outdated (being last updated in 2011), a more detailed comparison between Finale and Lilypond can be found here.

Your first score

Here is the most basic Lilypond score:

1 % LilyBin
2 \score{
3   {
4     c'
5   }
7   \layout{}
8   \midi{}
9 }
Try it yourself

Let’s walk through every line in this first example.

Line 1 – Everything preceded by a % is a comment that will be ignored by LilyPond

Line 2 – Every directive in Lilypond is preceded by a \. In this example there is \score \layout and \midi. Each of these are instructions to LilyPond about what to render. Most directives mark a block and are enclosed with curly braces.

  % stuff
  % inside a block

Line 4 – Here are the notes to be rendered. Try adding some notes here and see what happens. The ' means to go up an octave and , means to go down an octave. Try this:

 1 % LilyBin
 2 \score{
 3   {
 4     \clef bass
 5     c' c c,
 6   }
 8   \layout{}
 9   \midi{}
10 }
Try it yourself

Your first piano score

Now let’s add some more things to this to get a full piano score.

 1 \version "2.18.2"
 3 global = {
 4   \key c \major
 5   \time 4/4
 6 }
 8 right = \relative c' {
 9   \global
10   \clef treble
11   c4 d e f g1 \bar "|."
12 }
14 left = \relative c {
15   \global
16   \clef bass
17   c2 g' c,1
18 }
20 \score {
21   \new PianoStaff \with {
22     instrumentName = "Piano"
23   } <<
24     \new Staff = "right" \right
25     \new Staff = "left" \left
26   >>
27   \layout { }
28 }
Try it yourself

Again, let’s walk through this line by line.

Line 1 – This specifies the version of Lilypond with which the file is compatible. Sometimes something that will work in version 2.19 won’t work in version 2.18. Mostly this is for others when you share the file to let them know what version you were using.

Line 3 – A variable name. There are 3 variables in this file: global, right (line 8), and left (line 14). Variables are a handy way of saving you from typing out the same things multiple times. After the variable has been defined, you reference it with a \ then the variable name. So in line 9 \global is the same thing as writing out

 8 right = \relative c' {
 9   \key c \major
10   \time 4/4
11   \clef treble
12   c4 d e f g1 \bar "|."
13 }

A warning! Don’t use keywords for variable names, such as key or time. Lilypond needs these words so you shouldn’t redefine them.

Line 8\relative c' This sets all the notes in the block as relative to C4 or middle C. The other way of writing notes is absolute, meaning all notes are relative to C3. See the documentation for more on writing pitches.

Line 11 – The numbers following the note are the rhythmic value of the note. The note will stay the same value as the ones preceding it until the value is changed. So c4 d4 e4 f2 g2 c1 is the same as writing c4 d e f2 g c1.

Also the ordering matters. Don’t write c4,, instead write c,4. The , alters the c not the rhythm.

Rests, Rhythm, Ties, and Chords

Here’s a silly example with a bunch of random stuff in it for reference. I put this here partially for myself to have an easy reference.

 1 \version "2.18.2"
 3 \header {
 4   title = "Oh! Susanna"
 5   subtitle = "Don't you cry for me"
 6   instrument = "piano"
 7   composer = "Stephen Foster"
 8   copyright = "Public Domain"
 9   tagline = "This is a tagline"
10 }
12 global = {
13   \key c \major
14   \time 4/4
15 }
17 right = \relative c' {
18   \global
19   \clef treble
20   \partial 4
21   c8( d |
22   e4) g g4. a8 |
23   g4 e ~c4 ~c8 d8 |
24   ees4 e d cis |
25   d1 \bar "|."
26 }
28 left = \relative c {
29   \global
30   \clef bass
31   r4 |
32   <c e g>2 g4 a8-. b-. |
33   c2 g4 \tuplet 3/2 {g8 a b} |
34   c2 d4 s |
35   g1
36 }
38 \score {
39   \new PianoStaff \with {
40     instrumentName = "Piano"
41   } <<
42     \new Staff = "right" \right
43     \new Staff = "left" \left
44   >>
45   \layout { }
46 }
Try it yourself

After you have played with the example a bit, here are some thoughts.

Slurs (line 21 - 22) begin at the end of a note c8( and go until the note preceding the closing paren e4).

Ties (line 23) are marked with ~.

Chords (line 32) are placed within angle brackets <c e g>. If you are writing polyphonic music you will need to split up the voices for more control. See the documentation for more information.

Staccatos (line 32) are put in here with a shorthand a8-.. You could also do a8\staccato. See the documentation for more information.

Triplets (line 33) are enclosed in a new block. Be sure to give the note inside a note value and remember to restate the rhythm value after the tuplet is over.

Measure marks are denoted with |. This is the pipe character usually found in the upper right hand of the keyboard with the forward slash key. Lilypond will put bars in for you but this is just a convenient way to keep track of where you are visually in the code. If you place it in the wrong spot nothing bad will happen though.

Rests and spacers are denoted with r and s and are treated just like notes. I often use spacers for worksheets where I don’t want to show rests or notes.

Accidentals (line 24) are denoted by default with Dutch note naming convention as es (flat) or is (sharp). You can use other naming conventions with the \language setting. With \language english you could use flat or sharp (or shorthand f and s) like this:

\language english
    \clef bass
    bflat c dsharp
Try it yourself

You will want to eventually start using something like Frescobaldi or Demeno for writing your scores. You can use a midi keyboard for input. There is a Finale-like Score Wizard in Frescobaldi for quickly getting your scores started. Frescobaldi will also catch and highlight errors in your score so you can fix them.

That should get you started with making scores. Things I haven’t covered are dynamics, lyrics, chord analysis, lead sheets, and figured bass. Lilypond does this all very well. That will wait for another post.

comments powered by Disqus
Subscribe to our blog

Follow us on