Text Color in LaTeX

Use the xcolor package and \textcolor{}{} to color text in LaTeX.

Quick Answer

latex
\usepackage{xcolor}  % in preamble

\textcolor{red}{This text is red.}

Setup

Add \usepackage{xcolor} to your preamble. The package is included in all major LaTeX distributions — no extra installation needed.

Named Colors

xcolor provides 19 base colors out of the box. Load the dvipsnames option for 68 additional named colors.

latex
% Base colors (always available):
\textcolor{red}{Red text}
\textcolor{blue}{Blue text}
\textcolor{green}{Green text}
\textcolor{orange}{Orange text}
\textcolor{gray}{Gray text}

% Extended palette (add dvipsnames option):
\usepackage[dvipsnames]{xcolor}

\textcolor{MidnightBlue}{Midnight blue}
\textcolor{ForestGreen}{Forest green}
\textcolor{BrickRed}{Brick red}

Writing your thesis in LaTeX?

MonsterWriter's LaTeX Workspace gives you real-time PDF preview with no compile limits — at a fraction of Overleaf's price. Works just like Overleaf, costs 11× less.

Try MonsterWriter free

Custom Colors

Define your own colors with \definecolor. Supports RGB, HTML hex, and other color models.

latex
% Define in preamble:
\definecolor{myblue}{RGB}{67, 97, 238}
\definecolor{mygray}{HTML}{6B7280}
\definecolor{lightbg}{gray}{0.95}

% Use anywhere:
\textcolor{myblue}{Custom blue text}
\colorbox{lightbg}{Highlighted text}

Background Color

latex
% Colored box around text:
\colorbox{yellow}{Highlighted phrase}

% Full-page background (in preamble):
\pagecolor{lightgray}

% Colored text with colored background:
\colorbox{black}{\textcolor{white}{Inverted text}}

Color in Math Mode

latex
\[ \textcolor{red}{E} = \textcolor{blue}{m}\textcolor{green}{c^2} \]

% Color a whole equation:
\[ \color{MidnightBlue} F = ma \]

Related Topics