LaTeX Colors: xcolor Names, Custom Colors, Colored Text
Load xcolor, then use \textcolor for colored text and \definecolor for custom RGB or HTML colors.
\usepackage{xcolor}
\textcolor{red}{important}The xcolor package gives you access to named colors, custom color definitions, and commands for coloring text and backgrounds. It's one of the most widely used LaTeX packages.
Load the xcolor Package
Add xcolor to your preamble. The dvipsnames option provides 68 extra named colors (e.g., ForestGreen, RoyalBlue).
\usepackage[dvipsnames]{xcolor}
% Now you can use named colors like:
% red, blue, green, cyan, magenta, yellow, black, white,
% ForestGreen, RoyalBlue, Maroon, Orchid, etc.Color Text
Use \textcolor{color}{text} to change the color of specific text:
This word is \textcolor{red}{red} and this is \textcolor{blue}{blue}.
\textcolor{ForestGreen}{This entire sentence is forest green.}Background Colors
Use \colorbox{color}{text} to add a background color behind text:
\colorbox{yellow}{Highlighted text}
\colorbox{cyan!20}{Light cyan background}Define Custom Colors
Create your own colors using RGB, HTML hex, or CMYK values:
% RGB (0-255 values scaled to 0-1)
\definecolor{myblue}{RGB}{41, 128, 185}
% HTML hex
\definecolor{darkgold}{HTML}{B8860B}
% Mix existing colors
\definecolor{lightred}{red!30!white}
\textcolor{myblue}{Custom blue text}
\textcolor{darkgold}{Dark gold text}Colored Boxes with Frames
Use \fcolorbox for bordered colored boxes, or combine with tcolorbox for more advanced layouts:
% Simple framed color box
\fcolorbox{red}{yellow}{Warning: important text}
% For advanced boxes, use tcolorbox:
\usepackage{tcolorbox}
\begin{tcolorbox}[colback=blue!5, colframe=blue!50]
This is a styled box with a blue theme.
\end{tcolorbox}💡 Tips
- •Use color sparingly in academic papers—many journals prefer black and white
- •The ! operator mixes colors: red!30 means 30% red + 70% white
- •Use \color{red} (without text argument) to switch color for all following text until the group ends
- •For accessibility, avoid relying on color alone to convey meaning
Try This in Bibby AI
Write LaTeX faster with AI auto-complete and instant compilation.
Start Writing FreeNeed help with your bibliography or citations?
Book a Free Call