Color in LaTeX

To use color in LaTeX, load the xcolor package. Then \textcolor{red}{text} colors a few words, and {\color{blue} …} colors everything up to the end of the group.

LaTeX
This word is \textcolor{red}{red}, and {\color{blue} this phrase is blue}.
OutputA sentence with the word red in red and a phrase in blue.

Needs \usepackage{xcolor} in the preamble.

Full document you can compile
example.tex
\documentclass{article}
\usepackage{xcolor}
\begin{document}
This word is \textcolor{red}{red}, and {\color{blue} this phrase is blue}.
\end{document}

Which color names can you use?

Without options, xcolor knows 19 names: red, green, blue, cyan, magenta, yellow, black, gray, white, darkgray, lightgray, brown, lime, olive, orange, pink, purple, teal, violet. Load it as \usepackage[dvipsnames]{xcolor} for 68 more, such as ForestGreen and RoyalBlue; svgnames and x11names add the web and X11 color lists. Names are case-sensitive.

LaTeX
\textcolor{ForestGreen}{ForestGreen}, \textcolor{RoyalBlue}{RoyalBlue},
\textcolor{BrickRed}{BrickRed}, \textcolor{Orange}{Orange}
OutputThe names ForestGreen, RoyalBlue, BrickRed and Orange, each in its own color.

Needs \usepackage[dvipsnames]{xcolor} in the preamble.

Full document you can compile
example.tex
\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\begin{document}
\textcolor{ForestGreen}{ForestGreen}, \textcolor{RoyalBlue}{RoyalBlue},
\textcolor{BrickRed}{BrickRed}, \textcolor{Orange}{Orange}
\end{document}

How do you define your own color?

Use \definecolor{name}{model}{value} in the preamble. The HTML model takes a hex code without the #, RGB takes three numbers from 0 to 255, and rgb takes three numbers from 0 to 1. You can also mix colors on the spot: blue!40!black is 40% blue and 60% black, and red!20 is a light red.

LaTeX
\definecolor{brand}{HTML}{6D28D9}
\definecolor{sky}{RGB}{14,165,233}
\textcolor{brand}{HTML color 6D28D9}, \textcolor{sky}{RGB color 14,165,233},
\textcolor{blue!40!black}{a mix of blue and black}.
OutputText in a custom violet from an HTML code, a sky blue from RGB values, and a dark blue mixed from blue and black.

Needs \usepackage{xcolor} in the preamble.

Full document you can compile
example.tex
\documentclass{article}
\usepackage{xcolor}
\begin{document}
\definecolor{brand}{HTML}{6D28D9}
\definecolor{sky}{RGB}{14,165,233}
\textcolor{brand}{HTML color 6D28D9}, \textcolor{sky}{RGB color 14,165,233},
\textcolor{blue!40!black}{a mix of blue and black}.
\end{document}

How do you highlight text?

\colorbox{yellow}{…} puts a colored background behind the text, and \fcolorbox{red}{white}{…} adds a frame. Both keep the text on one line; for a highlight that breaks across lines, the soul package has \hl. \textcolor also works inside math.

LaTeX
\colorbox{yellow}{Highlighted text} and
\fcolorbox{red}{white}{a framed box}, and $x = \textcolor{red}{2}$.
OutputText on a yellow background, a box with a red frame, and a formula where the 2 is red.

Needs \usepackage{xcolor} in the preamble.

Full document you can compile
example.tex
\documentclass{article}
\usepackage{xcolor}
\begin{document}
\colorbox{yellow}{Highlighted text} and
\fcolorbox{red}{white}{a framed box}, and $x = \textcolor{red}{2}$.
\end{document}

How do you color a table row or a link?

For tables, load xcolor with the table option and use \rowcolor{gray!15} at the start of a row. For links made with hyperref, set \hypersetup{colorlinks=true, linkcolor=blue}; the hyperlinks guide covers the details.

Do LaTeX colors carry over to a web page?

Not as is. The LaTeX to HTML converter keeps the text of \textcolor but drops the color, because names such as ForestGreen aren't CSS colors; add a CSS class to the result instead. Inside formulas, \textcolor works in the equation editor. For other text styles, see the bold guide. Size is set separately, as the font size guide explains.

Text drafted with AI from the xcolor documentation; every example compiled with TeX Live 2026; checked by Cem Demir. See the editorial policy.