Written and maintained by CASRAI Editorial Board
Last updated
Short answer: load the xcolor package, then write \textcolor{red}{some words} to colour a few words or {\color{red} some words} to colour everything inside a group. \textcolor takes the colour first and the text second; \color is a switch that stays on until its group or environment ends.
What it is used for in research
Coloured text in a LaTeX manuscript, thesis, poster or set of slides is used to flag revisions during co-authoring, mark variables or results in an equation walk-through, or keep a consistent palette across figures and text. Journals often print in greyscale or restrict colour, so check the target venue’s author instructions before relying on colour alone to carry meaning (see boldface in LaTeX for an emphasis cue that does not depend on colour).
Install or access (official source only)
xcolor is the driver-independent colour extension for LaTeX and pdfLaTeX. It builds on the basic color package and adds tints, shades, tones and mixes, with eight colour models. The CTAN entry lists version 3.02 dated 2024-09-29 under the LaTeX Project Public Licence 1.3c, with documentation in xcolor.pdf and development at github.com/latex3/xcolor (CTAN, read 2026-11-07). Load it in the preamble:
\usepackage{xcolor}
Step-by-step: colour text in LaTeX
1. Colour a few words with textcolor
- Add
\usepackage{xcolor}to the preamble. - In the body, write
\textcolor{red}{easily}. The first argument is the colour, the second is the text (Overleaf, read 2026-11-07).
2. Colour a block with color
- Write
\color{blue}where the colour should begin. It sets the colour for the current block of text, for example inside anitemizeenvironment. - To keep the change local, put the switch inside braces:
{\color{red} \rule{linewidth}{0.5mm}}. The group confines the change.
3. Define your own colour
- Use
\definecolor{name}{model}{definition}in the preamble, then use the name in\textcoloror\color:
\definecolor{mypink1}{rgb}{0.858, 0.188, 0.478}
\definecolor{mypink2}{RGB}{219, 48, 122}
\definecolor{mypink3}{cmyk}{0, 0.7808, 0.4429, 0.1412}
\definecolor{mygray}{gray}{0.6}
\definecolor{Mycolor2}{HTML}{00F9DE}
\textcolor{mypink1}{Pink with rgb}
4. Mix colours or use a named set
- Mix with
\colorlet, for example\colorlet{Mycolor1}{green!10!orange}, or tint a named colour with\colorlet{LightRubineRed}{RubineRed!70}. - For extra named colours, pass an option when loading:
\usepackage[dvipsnames]{xcolor}. Basic names such asredandblueneed no option. - For a coloured background behind text,
\colorbox{color}{text}takes the background colour first and the text second. For boxed layouts see framed boxes in LaTeX and tcolorbox examples.
Output and how to read it
The compiled PDF shows the chosen words in the requested colour; the rest of the paragraph keeps the default colour. If a whole list or section turns the colour, a \color switch was not closed in a group. \pagecolor{black} followed by \color{white} sets a dark page with white default text, and \nopagecolor restores the normal background (Overleaf).
Colour models at a glance
| Model | Values |
|---|---|
rgb |
three numbers from 0 to 1 |
RGB |
three integers from 0 to 255 (xcolor) |
cmyk |
four numbers from 0 to 1 |
gray |
one number from 0 to 1 |
HTML |
six hexadecimal digits, A to F in uppercase (xcolor) |
hsb, cmy, Gray (1 to 15), wave (363 to 814 nm) |
additional xcolor models |
Named sets loaded by option: dvipsnames has 68 CMYK colours, svgnames has 151 RGB colours and x11names has 317 RGB colours (Overleaf, read 2026-11-07).
textcolor versus color
| textcolor | color | |
|---|---|---|
| Form | \textcolor{red}{text} |
\color{red} |
| Applies to | the text in its second argument | the current block, confined by braces when grouped |
| Typical use | a word or phrase in a sentence | a list, a block, or a rule inside braces |
Troubleshooting
- Wrong colour or nothing coloured: check argument order.
\textcolortakes colour, then text;\colorboxtakes background colour, then text. - Colour carries into later text: wrap the
\colorswitch in braces so it stays local. - Undefined colour name: names beyond the basics need an option such as
dvipsnames,svgnamesorx11nameson\usepackage{xcolor}, or a\definecolorin the preamble. - HTML colour rejected: use exactly six hexadecimal digits with A to F in uppercase, for example
00F9DE. - Unexpected shade:
rgbexpects values from 0 to 1 whileRGBexpects integers from 0 to 255; do not mix the ranges.
Free alternatives
| Package | What the sources say |
|---|---|
\color |
The basic colour package that xcolor builds on (CTAN, read 2026-11-07) |
xcolor |
Recommended over \color by Overleaf for its flexibility and extra models; adds tints, shades, tones and mixes; LPPL 1.3c licence (CTAN) |
For coloured code listings see LaTeX listings; for strike-through marks see cross-out in LaTeX.
FAQ
How do I change text colour in LaTeX?
Load xcolor and use \textcolor{colourname}{text} for a phrase or {\color{colourname} text} for a group.
What is the difference between textcolor and color?
\textcolor colours only its argument. \color changes the colour for the current block, so wrap it in braces to limit its reach.
Can I use hex colour codes?
Yes, through xcolor’s HTML model: \definecolor{Mycolor2}{HTML}{00F9DE}, with six hexadecimal digits and A to F in uppercase.
How do I put a background colour behind text?
Use \colorbox{color}{text}; the colour in the first argument is the background.
Sources
- CTAN, xcolor package entry, read 2026-11-07.
- Overleaf documentation, Using colours in LaTeX, read 2026-11-07.







