Reference manual/Quick reference
THE QUICK REFERENCE

A little color, step by step.

Start with a color name. Continue to custom definitions when your document needs them.

Basic use

For most documents, you can work entirely with color names. Choose a color from the library, load its set, and place the name inside a coloring command. The same name can color a heading, emphasize a sentence, or tint a table row. You do not need to choose a numeric color model to get started.

Load xcolor before the document begins

The preamble is the part of a LaTeX file before \begin{document}. Load xcolor there, together with the other packages your document uses. The svgnames option makes names such as SlateBlue available; the example below uses that name to color a short sentence.

\documentclass{article}
\usepackage[svgnames]{xcolor}

\begin{document}
\textcolor{SlateBlue}{Hello, color!}
\end{document}

If you already load xcolor, edit the existing package line to add the options you need. Loading it again with different options can cause an “Option clash” error. When a document class or another package loads it for you, pass the required options before that class or package is loaded.

Choose a name from the right set

A color set is a collection of ready-to-use names. The color library labels each color with its set, and each color’s guide gives you the matching package line. Start with one set; you can add another if it contains a name you need.

Base colors
The 19 built-in names, including black, blue and teal, work with \usepackage{xcolor} alone.
dvipsnames
Add dvipsnames to load 68 traditional names such as RoyalBlue and Apricot.
svgnames
Add svgnames to load 151 names such as SlateBlue and Tomato, including spelling aliases.
x11names
Add x11names to load 317 names. Numbered variations such as Snow1 let you choose between related shades.

Names are case-sensitive: blue and Blue are different identifiers. A name shared by several sets can also have a different definition in each one. If you combine sets, read the note on overlapping names before relying on a shared name.

Color just the text you want to emphasize

Use \textcolor when the colored content is a word, sentence, or heading. Its first argument is the color; its second is the content. The surrounding text keeps its current color, so emphasis stays local.

This sentence stays black.
\textcolor{SlateBlue}{This sentence is colored.}
This sentence stays black again.

For a longer passage, \color changes the current color until the surrounding group ends. The braces in the following example are the boundary of that change. Keep them around the passage so that later paragraphs do not inherit its color.

{\color{SlateBlue}
This passage is colored.

A second paragraph can share the same color.
}
This passage uses the original color.

To see a heading, paragraph and equation together, try the paper simulator. It keeps the page white and lets you adjust each effect independently.

Add a background without changing the text color

A background is a separate choice from a foreground color. \colorbox puts a colored rectangle behind its content while the text keeps its current color. A light tint is often a useful starting point for readable highlights. If you also want a border, \fcolorbox takes a frame color, a fill color, and then the content.

\colorbox{SlateBlue!20}{Highlighted text}
\fcolorbox{SlateBlue}{white}{Text with a colored border}

These commands make boxes, so their contents do not automatically wrap like an ordinary paragraph. Use them for short passages; the advanced section explains how to give a longer passage a width. The !20 in the first example is a tint, which we will read next.

Read a mix as a percentage of the first color

To soften a color, add a percentage after its name. SlateBlue!40 means 40% SlateBlue mixed with 60% white. White is the default second color, so SlateBlue!40!white means the same thing.

You can replace white with any available color. SlateBlue!40!black makes a darker shade, while red!50!blue mixes equal parts red and blue. The percentage always belongs to the color on its left. Use a smaller percentage for more of the second color, or a larger one for more of the first.

\textcolor{SlateBlue!40}{A lighter foreground}
\colorbox{SlateBlue!10}{A subtle background}
\textcolor{red!50!blue}{An equal blend}

A mix works wherever a command accepts a color name; you do not have to define it first. Experiment in the color mixer, then copy the expression into your document. Chained mixes and color functions are covered under advanced expressions.

Carry the same colors into a table

Add the table package option when you want colored rows or cells. This enables the table coloring commands through colortbl. A useful first pattern is alternating pale rows: \rowcolors takes a starting row number, an odd-row color and an even-row color. Starting at row 2 leaves the header uncolored in this example.

\documentclass{article}
\usepackage[table,svgnames]{xcolor}

\begin{document}
\rowcolors{2}{SlateBlue!10}{white}
\begin{tabular}{lr}
Method & Accuracy \\
Baseline & 0.842 \\
Adaptive & 0.917 \\
\end{tabular}
\end{document}

For one cell, place \cellcolor{SlateBlue!20} inside that cell. For an entire row, put \rowcolor{SlateBlue!20} at the beginning of the row. Ordinary \textcolor still works inside cells when only the text should change. The table simulator lets you compare text color, text highlights and cell fills on the same table.

Advanced use

Named colors and percentage mixes cover everyday emphasis. Continue here when you need an exact specification, a reusable document palette, controlled color conversion, or a generated sequence of shades. These tools give you more control over how a color is defined and interpreted.

Give an exact color a name of your own

If your publisher or organization supplies a numeric color specification, define it with \definecolor. The arguments are the new name, the color model and the values in that model. For a six-digit web color, use HTML and omit the leading # character.

% Put the definition in the preamble.
\definecolor{brand}{HTML}{664DCC}

% Use the name in the document body.
\textcolor{brand}{Text in the exact brand color}

If you already have the color as a name or expression, use \colorlet instead. It saves the result of that expression under another name. This is useful for a repeated role such as a note background: you can update the palette in one place while the document continues to use that role’s name.

\colorlet{noteBackground}{SlateBlue!15}
\colorbox{noteBackground}{A reusable note color}

Choose a model that matches your source values

A set tells you which names are available; a model tells xcolor how to interpret numbers. For example, rgb uses fractional red, green and blue channels, whereas RGB uses integers from 0 to 255 by default. Those identifiers are case-sensitive. Use the model supplied with your values rather than relabeling the numbers as a different model.

For screen specifications, HTML or RGB is often convenient. Use cmyk when you have process-color values, gray for grayscale, and a hue-based model when your calculation is expressed as hue, saturation and brightness. The table below covers all 12 numeric models and the two special pseudo models.

ModelComponentsRange / specificationExample values
rgbRed, green, blue0–1 per channel0.4,0.3,0.8
cmyCyan, magenta, yellow0–1 per channel0.6,0.7,0.2
cmykCyan, magenta, yellow, black0–1 per channel0.3,0.4,0,0.2
hsbHue, saturation, brightness0–1 per channel0.7,0.6,0.8
grayGrayscale intensity0 = black, 1 = white0.5
RGBInteger red, green, blue0–255 (default rangeRGB)102,77,204
HTMLHexadecimal red, green, blueSix hex digits; no # prefix664DCC
HSBInteger hue, saturation, brightness0–240 (default rangeHSB)168,144,192
GrayInteger grayscale0–15 (default rangeGray)8
HsbHue in degrees, saturation, brightness0–360, 0–1, 0–1 (default rangeHsb)252,0.6,0.8
tHsbTuned hue, saturation, brightness0–360, 0–1, 0–1; configurable hue mapping252,0.6,0.8
waveWavelength of visible light363–814 nm yields a nonblack color485
namedA driver-provided or existing named colorName; conversion is one wayForestGreen
psPostScript color specificationDriver-specific PostScript code0.4 0.3 0.8 setrgbcolor

The integer ranges shown here are defaults and can be configured. tHsb uses \rangetHsb for a tuned hue mapping. The special named model refers to an available named color; the ForestGreen example needs dvipsnames. The ps model contains driver-specific PostScript code and requires a compatible driver; TeX cannot numerically convert it.

Convert values when another tool expects a different model

Changing a model means converting its values, rather than keeping the same numbers and changing the label. \convertcolorspec takes the source model and values, the target model, and a macro in which to store the converted values. This example stores the fractional RGB equivalent of a hexadecimal specification in \brandRGB.

\convertcolorspec{HTML}{664DCC}{rgb}\brandRGB
\definecolor{convertedBrand}{rgb}{\brandRGB}

You can also ask xcolor to use a target model throughout a document, for example with \usepackage[rgb,svgnames]{xcolor} or \selectcolormodel{rgb}. In its natural mode, xcolor keeps colors in their own models; a percentage expression is mixed in the first color’s model. A target model makes those conversions consistent across colors from different sources. Numeric conversion does not account for a printer’s color profile, so screen and printed results can still differ.

Be deliberate when sets share a name

Loading more sets makes more names available, but it can also replace a definition you already use. For example, Green from dvipsnames differs from Green in svgnames. xcolor loads dvipsnames, then svgnames, then x11names, regardless of the order in the option list. A later set wins for any name it defines again.

When you only need a few additional names, a starred option prepares a set without immediately activating all its names. Use \definecolors to activate the ones you want. In the following example, SlateBlue and Tomato become available while the other SVG names remain deferred.

% In the preamble:
\usepackage[svgnames*]{xcolor}
\definecolors{SlateBlue,Tomato}

% In the document body:
\textcolor{SlateBlue}{An explicitly activated color}

Activating a name can still replace an existing definition with that name. \providecolors only defines a prepared name if it is not already defined. If the same spelling must represent two different colors in one document, give those definitions distinct names rather than relying on the package option order.

Build more than a two-color blend

A chained expression is evaluated from left to right. In red!50!blue!20!white, xcolor first mixes red and blue equally, then mixes 20% of that result with 80% white. A leading minus sign, as in -SlateBlue, requests a complementary color.

Extended expressions let you work with several weighted colors in an explicit model. rgb:red,1;green,2;blue,3 uses weights 1, 2 and 3, normalized by their sum. Color functions perform another operation on the result: red>wheel,120 rotates the hue by 120 degrees while keeping saturation and brightness unchanged.

\textcolor{rgb:red,1;green,2;blue,3}{A weighted RGB blend}
\textcolor{red>wheel,120}{A hue rotation}

For repeated steps, define a color series rather than writing every shade by hand. A series has a starting color, a rule for the next color, and an initialization step. Here the last method moves from blue toward red; resetting with 5 divides that interval into five steps. Each !!+ access advances the series after using its current color.

\definecolorseries{sequence}{rgb}{last}{blue}{red}
\resetcolorseries[5]{sequence}
\textcolor{sequence!!+}{First shade}
\textcolor{sequence!!+}{Next shade}

These expressions are evaluated by LaTeX. The website’s mixer and simulator cover named colors and percentage blends. For the complete grammar and series methods, consult the official xcolor manual .

Apply color to a larger part of the document

For a paragraph background, place a width-constrained \parbox inside the color box. The text can then wrap within that width. Subtracting twice \fboxsep accounts for the box’s left and right padding, so the total width stays within the current line width.

\noindent\colorbox{SlateBlue!10}{%
  \parbox{\dimexpr\linewidth-2\fboxsep}{%
    A longer note can wrap across several lines inside this box.%
  }%
}

To change the entire page background, use \pagecolor. This affects the page background rather than the text color, and remains active until changed or cleared. \nopagecolor removes that page-color setting; it is different from explicitly painting a page white.

\pagecolor{SlateBlue!5}
% Pages use this background until it is changed or cleared.
\nopagecolor
Based on xcolor v3.02 documentation and the official source. Use the color library to find names and the simulator to explore their effect in a document.