Coloring objects

Individual objects may be assigned colors. Valid color names are listed in the List of colors.

\override NoteHead.color = #red
c''4 c''
\override NoteHead.color = #(x11-color 'SlateGrey)
d''
\override Stem.color = "deepskyblue"
e''

[image of music]

In addition to a limited set of simple colors available as predefined variables (see ‘Normal colors’ in List of colors), any color may be entered as a string. That string may be either a CSS-style predefined color name, or a hexadecimal color code prefixed by the ‘#’ character (inside the double quotes):

\override NoteHead.color = "lightsalmon"
\override Flag.color = "#E30074"
\override Beam.color = "#5e45ad"
\override Rest.color = "#3058"
g'8 \huge r4 a'16 f'

[image of music]

If that color code includes an alpha channel for semi-transparency, by using an eight-character code "#RRGGBBAA" or its shorthand form "#RGBA", it will be used in SVG output but not in PostScript/PDF output. In the previous example, the rest can be seen through only if the code is compiled with the SVG backend, as explained in Alternative output formats.

In a different way, the full range of colors defined for X11 can be accessed by using the Scheme function x11-color. That function takes one argument, which can be a symbol, such as 'DarkSeaGreen4, or a string, such as "DarkSeaGreen4". The first form is quicker to write and slightly more efficient; however, the second form also makes it possible to specify X11 colors as multiple words: in this instance, "dark sea green 4".

If x11-color cannot make sense of the parameter, then the color returned defaults to black.

\new Staff \with {
  instrumentName = \markup {
    \with-color #(x11-color 'SlateGrey) "Clarinet"
    }
  }
  \relative c'' {
  \override Staff.StaffSymbol.color = #(x11-color 'SlateBlue2)
  gis8 a
  \override Beam.color = #(x11-color "medium turquoise")
  gis a
  \override Accidental.color = #(x11-color 'orange)
  gis a
  \override NoteHead.color = #(x11-color "LimeGreen")
  gis a
  % this is deliberate nonsense; note that the stems remain black
  \override Stem.color = #(x11-color 'Boggle)
  b2 cis
}

[image of music]

LilyPond also supports a set of eight color names that is unambiguous to both color-blind and non-color-blind people. Use universal-color to access them.

\markup \with-color #(universal-color 'vermillion) vermillion

[image of music]

Exact RGB colors can be specified using the Scheme function rgb-color. This function takes three arguments used respectively for the red, green and blue channels, and an optional alpha number for semi-transparency. (All values must be numbers from 0 to 1.) Again, transparency is only supported in SVG output; for example, in the following fragment the staff’s clef can be seen through when rendered in SVG.

\new Staff \with {
    instrumentName = \markup {
      \with-color #(x11-color 'red) "Clarinet"
      }
    \override Clef.color = #(rgb-color 0 0 0 0.5)
  }
\relative c'' {
  \override Staff.StaffSymbol.color = #(x11-color 'SlateBlue2)
  \override Stem.color = #(rgb-color 0 0 0)
  gis8 a
  \override Stem.color = #(rgb-color 1 1 1)
  gis8 a
  \override Stem.color = #(rgb-color 0 0 0.5)
  gis4 a
}

[image of music]

See also

Notation Reference: List of colors, \tweak and \single.

Snippets: Editorial annotations.

Known issues and warnings

An X11 color is not necessarily exactly the same shade as a similarly named normal color.

Not all X11 colors are distinguishable in a web browser, i.e., a web browser might not display a difference between LimeGreen and ForestGreen. For web use CSS colors are recommended, as detailed in List of colors.

Notes in a chord cannot be separately colored with \override; use \tweak or the equivalent \single\override before the respective note instead, see section \tweak and \single.


LilyPond Notation Reference v2.25.13 (development-branch).