Colors in LaTeX: xcolor, Named Colors and Custom Colors

November 11, 2026 · 11 min read

Colors in LaTeX: xcolor Commands, Named Colors and Custom Colors

Colors in LaTeX come from the xcolor package. Load it with \usepackage{xcolor}, then write \textcolor{red}{text} for one phrase or \color{red} for everything after it. You get 19 color names out of the box, 68 more with the dvipsnames option, and \definecolor for any RGB, hex or CMYK value.

Below you'll find the 19 base names and all 68 dvipsnames as copyable text, one line per color model, and the mixing syntax. The last section shows what still works when KaTeX renders the same LaTeX on a web page.

How Do You Load xcolor to Use Colors in LaTeX?

xcolor, written by Uwe Kern and now maintained by the LaTeX Project team, extends the older color package from LaTeX's graphics bundle. CTAN lists v3.02, dated 2024-09-29, as the current release. Load it once in the preamble. It covers everything color does, so you don't need to load both.

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

\begin{document}
This word is \textcolor{red}{red}, and this one is \textcolor{ForestGreen}{ForestGreen}.
\end{document}

The PDF shows one sentence with "red" in pure red and "ForestGreen" in a bright green. Without the dvipsnames option, the second command stops with Undefined color 'ForestGreen'. If your text starts life as Markdown, convert it to LaTeX with Pandoc first, then add the colors.

The options you'll actually use:

OptionWhat it adds
dvipsnames68 CMYK names such as RoyalBlue and BrickRed
svgnames151 RGB names from the SVG 1.1 color list
x11names317 RGB names from the X11 rgb.txt file
tableLoads the colortbl package for row and cell colors

Packages such as TikZ load xcolor on their own. Since xcolor v3.00 (November 2023), a later \usepackage[dvipsnames]{xcolor} still applies its options, as it did in our TeX Live 2025 test. On older TeX installations that order triggers an "Option clash for package xcolor" error. The fix there is \PassOptionsToPackage{dvipsnames}{xcolor} as the very first line, before \documentclass.

\textcolor vs \color: One Phrase or Everything After It

The two commands set the same color in different ways. \textcolor{name}{text} colors only its second argument and then reverts. \color{name} is a switch: per the xcolor manual, it stays in effect until the end of the current TeX group.

{\color{blue} Only this group is blue.} Back to black.

\textcolor{blue}{Only this phrase is blue.} Back to black.

Before. \color{blue} Everything from here on is blue,
including the next paragraph and the one after that.

The first two lines show the two safe forms: a braced group, or \textcolor, which adds the group for you. The last one is the classic leak. With no enclosing braces, the blue runs on until the environment or the document ends.

Both commands work in math mode too. In $x = \color{red} y + z$, the switch colors y + z, because the math formula is the group. Inside an environment such as center, a bare \color ends with \end{center}.

We prefer \textcolor in body text, because you can see exactly where the color starts and stops. Save \color for whole environments, table cells and captions, where the group already exists. One more limit: text color doesn't recolor images you add with \includegraphics, as the xcolor manual points out.

What Colors Are Available in LaTeX?

Plain xcolor defines 19 names, always available, all lowercase:

GroupBase color names (no option needed)
Primary and secondaryred, green, blue, cyan, magenta, yellow
Neutralsblack, darkgray, gray, lightgray, white
Everything elsebrown, lime, olive, orange, pink, purple, teal, violet

Add the dvipsnames option and you get 68 more. The xcolor manual (section 4.2) lists them alphabetically. We've grouped them by hue so you can find a shade fast:

Hue familydvipsnames (case-sensitive)
Yellows and oranges (11)Yellow, Goldenrod, Dandelion, Apricot, Peach, Melon, YellowOrange, Orange, BurntOrange, Bittersweet, RedOrange
Reds (8)Mahogany, Maroon, BrickRed, Red, OrangeRed, RubineRed, WildStrawberry, Salmon
Pinks and magentas (7)CarnationPink, Magenta, VioletRed, Rhodamine, Mulberry, RedViolet, Lavender
Purples and violets (10)Fuchsia, Thistle, Orchid, DarkOrchid, Purple, Plum, Violet, RoyalPurple, BlueViolet, Periwinkle
Blues and cyans (12)CadetBlue, CornflowerBlue, MidnightBlue, NavyBlue, RoyalBlue, Blue, Cerulean, Cyan, ProcessBlue, SkyBlue, Turquoise, TealBlue
Greens (13)Aquamarine, BlueGreen, Emerald, JungleGreen, SeaGreen, Green, ForestGreen, PineGreen, LimeGreen, YellowGreen, SpringGreen, OliveGreen, GreenYellow
Browns (4)RawSienna, Sepia, Brown, Tan
Neutrals (3)Gray, Black, White

Spelling matters. ForestGreen works, while forestgreen stops with an undefined color error. Red and red are two separate definitions: the capitalized one is the CMYK version from dvips.

Every name in both tables works wherever xcolor expects a color: \textcolor, \color, \pagecolor, and as the fill of a \colorbox. So the colorbox colors LaTeX accepts are these same names, plus the svgnames and x11names sets below and anything you define yourself. Frames, padding and box styles are a separate topic from the colors themselves.

svgnames and x11names: 468 More Named Colors

When 87 names aren't enough, two more options add 468. svgnames loads 151 RGB names: the SVG 1.1 color keywords plus four from X11. They're the same colors CSS uses, written in CamelCase, so DarkSlateGray in LaTeX is darkslategray in a stylesheet. Some are duplicates (Gray and Grey, Aqua and Cyan), so the 151 names cover 141 distinct colors.

x11names loads 317 names from the X11 rgb.txt file, all numbered variants such as DodgerBlue1 to DodgerBlue4. It skips the unnumbered names, because in X11 they match the SVG colors of the same name. Five X11 originals differ, so they come with a zero suffix: Gray0, Grey0, Green0, Maroon0 and Purple0.

Loading dvipsnames and svgnames together causes a quiet clash. Where both sets share a name, only one value survives. Fuchsia is purple in dvipsnames and bright magenta in svgnames. The manual says svgnames always wins, but in our TeX Live 2025 test with xcolor v3.02, the option listed last won. Don't rely on the order. Use the manual's starred, deferred form:

\usepackage[dvipsnames*,svgnames]{xcolor}
\definecolors{Fuchsia}

Now every SVG color is available, and Fuchsia comes from the dvips set. For swatches of all 468 names, see section 4 of the xcolor manual.

How Do I Define a Color in LaTeX With RGB, Hex or CMYK?

\definecolor{name}{model}{values} gives any value a name. Each model takes its own range:

ModelValuesExample
rgbThree decimals from 0 to 1\definecolor{brand}{rgb}{0.12,0.47,0.71}
RGBThree integers from 0 to 255\definecolor{brand}{RGB}{31,119,180}
HTMLExactly six hex digits, no #\definecolor{brand}{HTML}{1F77B4}
cmykFour decimals from 0 to 1\definecolor{ink}{cmyk}{1,0,0,0.2}
grayOne decimal, 0 is black\definecolor{mid}{gray}{0.5}

The first three rows define the same blue, give or take rounding. The HTML model accepts uppercase and lowercase digits alike, per the manual. Leave out the #, though: \textcolor{#1F77B4}{...} fails, because # is a special character in TeX.

For a one-off color, skip the name and pass the model in square brackets:

\textcolor[HTML]{1F77B4}{one-off hex blue}
\textcolor[RGB]{31,119,180}{the same blue as RGB}
\colorlet{note}{brand!20}
\colorlet{softgreen}{ForestGreen!40}

\colorlet{new}{expression} saves the result of any color expression under a new name. That's how you build a palette from one brand color. Put definitions in the preamble so they apply everywhere. One defined inside the document body only lasts until its group ends. \providecolor works like \definecolor but skips names that already exist.

Mixing and Tinting Colors With the ! Syntax

xcolor's expression syntax mixes colors inline, with no definition needed. red!30 means 30% red and 70% white. Add a second color to mix with something other than white.

\textcolor{red!30}{a pale pink tint}
\textcolor{red!30!black}{a dark red shade}
\textcolor{blue!50!green}{half blue, half green}
\textcolor{-red}{the complement of red}
\textcolor{red!50!green!20!blue}{a chained mix}

The first line is 30% red with white, a light pink. The second mixes 30% red with 70% black. The fourth line's leading minus gives the complementary color, which for red is cyan. Chains are read left to right: the 50/50 red-green mix becomes 20% of a new mix with blue.

Expressions work anywhere a color name does, including \colorbox and \rowcolor. The manual warns that color commands from other packages, such as soul's \sethlcolor, may give unexpected results with expressions. If one does, wrap the mix in \colorlet first and pass the name instead.

Page Backgrounds, Table Cells and Link Colors

\pagecolor{yellow!10} tints the current page and every page after it. Unlike \color, it's global and ignores groups. \nopagecolor switches back to the default transparent background.

For tables, load xcolor with the table option. It pulls in colortbl, which provides \rowcolor, \columncolor and \cellcolor:

\usepackage[table,dvipsnames]{xcolor}
% inside a tabular:
\rowcolor{gray!20} Name & Value \\
\cellcolor{Apricot} A & 1 \\

The LaTeX table generator builds the plain tabular and its column spec for you. Paste its output into your document, then add the color commands row by row.

Hyperlinks take xcolor names too. With hyperref, set colorlinks=true and pass any name from the tables above to each link type:

\hypersetup{colorlinks=true, linkcolor=NavyBlue,
  urlcolor=Maroon, citecolor=ForestGreen}

Colors in LaTeX on the Web: What KaTeX Supports

KaTeX, the math renderer behind many docs sites and Markdown editors, supports \color, \textcolor, \colorbox and \fcolorbox. Per the KaTeX function list, they accept HTML color names and CSS hex codes, with the # optional before six digits. Most of xcolor doesn't carry over:

FeatureLaTeX with xcolorKaTeX
\textcolor, \color, \colorbox, \fcolorboxYesYes
The 19 base namesYesYes, in CSS shades (CSS green is darker, CSS darkgray is lighter than gray)
dvipsnamesWith the optionOnly names that are also CSS colors
Hex code[HTML]{1F77B4}#1F77B4 or 1F77B4
\definecolor, \colorletYesNo, undefined control sequence
Mixing such as red!30YesNo, Invalid color error

Unknown names fail silently. KaTeX passes RubineRed straight to the browser as a CSS color, the browser ignores it, and the text stays in its default color. ForestGreen does render, because CSS names ignore case, but you get CSS forestgreen rather than the brighter dvips shade. MathJax, which GitHub uses for Markdown math, is closer to LaTeX here: per its documentation, its color extension adds \definecolor and the dvips color names. Our MathJax LaTeX guide shows how to add MathJax to a web page.

For coloring ordinary Markdown text rather than math, see our guide to Markdown text color. For math syntax in general, read how to write equations in Markdown. The demo below runs KaTeX inside our editor's preview:

Colors in LaTeX, rendered by KaTeX

Text color: E=mc2\textcolor{red}{E} = mc^2

Color switch: a2+b2=c2\color{teal} a^2 + b^2 = c^2

Hex code: f(x)=x2\textcolor{#1F77B4}{f(x)} = x^2

x+y=z\colorbox{yellow}{$\color{black} x+y$} = \textcolor{orange}{z}

Swap red for any CSS color name, such as crimson or slateblue, and watch the preview update.

47 words334 characters13 lines
Markdown

Our editor previews with KaTeX, not a full LaTeX engine, so it can't show dvipsnames or mixed colors as xcolor would. To export a colored equation as a PNG or SVG image, use the LaTeX equation editor.

Colors in LaTeX come down to three moves. Load xcolor with the name set you need, pick \textcolor or a scoped \color, and define the rest with \definecolor or a ! mix. Keep the tables above open while you work. To check how colored math looks on the web, paste it into the editor and compare the KaTeX preview with your PDF.