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.
This word is \textcolor{red}{red}, and {\color{blue} this phrase is blue}.Needs \usepackage{xcolor} in the preamble.
Full document you can compile
\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.
\textcolor{ForestGreen}{ForestGreen}, \textcolor{RoyalBlue}{RoyalBlue},
\textcolor{BrickRed}{BrickRed}, \textcolor{Orange}{Orange}Needs \usepackage[dvipsnames]{xcolor} in the preamble.
Full document you can compile
\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.
\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}.Needs \usepackage{xcolor} in the preamble.
Full document you can compile
\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.
\colorbox{yellow}{Highlighted text} and
\fcolorbox{red}{white}{a framed box}, and $x = \textcolor{red}{2}$.Needs \usepackage{xcolor} in the preamble.
Full document you can compile
\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.
Sources
- xcolor package documentation (CTAN), read Nov 28, 2026
- soul package documentation (CTAN), read Nov 28, 2026
Text drafted with AI from the xcolor documentation; every example compiled with TeX Live 2026; checked by Cem Demir. See the editorial policy.