14.9 Colors for Faces
Faces can have various foreground and background colors. When you specify a color for a faceβfor instance, when customizing the face (see Face Customization)βyou can use either a color name or an RGB triplet.
14.9.1 Color Namesβ
A color name is a pre-defined name, such as βdark orange
β or βmedium sea green
β. To view a list of color names, type M-x list-colors-display
. To control the order in which colors are shown, customize list-colors-sort
. If you run this command on a graphical display, it shows the full range of color names known to Emacs (these are the standard X11 color names, defined in Xβs rgb.txt
file). If you run the command on a text terminal, it shows only a small subset of colors that can be safely displayed on such terminals. However, Emacs understands X11 color names even on text terminals; if a face is given a color specified by an X11 color name, it is displayed using the closest-matching terminal color.
14.9.2 RGB Tripletsβ
An RGB triplet is a string of the form β#RRGGBB
β. Each of the primary color components is represented by a hexadecimal number between β00
β (intensity 0) and βFF
β (the maximum intensity). It is also possible to use one, three, or four hex digits for each component, so βred
β can be represented as β#F00
β, β#fff000000
β, or β#ffff00000000
β. The components must have the same number of digits. For hexadecimal values A to F, either upper or lower case are acceptable.
The M-x list-colors-display
command also shows the equivalent RGB triplet for each named color. For instance, βmedium sea green
β is equivalent to β#3CB371
β.
You can change the foreground and background colors of a face with M-x set-face-foreground
and M-x set-face-background
. These commands prompt in the minibuffer for a face name and a color, with completion, and then set that face to use the specified color. They affect the face colors on all frames, but their effects do not persist for future Emacs sessions, unlike using the customization buffer or X resources. You can also use frame parameters to set foreground and background colors for a specific frame; See Frame Parameters.