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}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 \]