How to Change Text Color in LaTeX
Load \usepackage{xcolor} and write \textcolor{red}{this text} for a few words, or {\color{blue} …} to color everything until the closing brace. Define your own colors with \definecolor{brand}{HTML}{1F6FEB}. The same commands color parts of equations.
Color commands (xcolor)
\textcolor{red}{x}Color one argument.
{\color{blue} x + y}Color from here to the end of the group.
- Text mode, no math preview
\definecolor{brand}{HTML}{1F6FEB}Custom color from a hex code; also
{RGB}{31,111,235}. - Text mode, no math preview
\textcolor{red!50}{x}Mix: red at 50% with white (xcolor syntax).
\colorbox{yellow}{x}Background highlight.
\fcolorbox{red}{yellow}{x}Highlight with a colored frame.
Try it live
Change the formula and the preview redraws as you type. Copy the LaTeX, download a PNG or SVG, copy it for Word, or use Edit here on any example below to load it.
Text color examples
Each result below is drawn from the LaTeX under it. Copy the code, edit it on this page, or open it in the full editor.
Highlighting terms
LaTeXf(x) = \textcolor{blue}{a}x^2 + \textcolor{red}{b}x + \textcolor{green}{c}Coloring a step
LaTeX(a + b)^2 = a^2 + \color{red}{2ab} + b^2Highlighted result
LaTeX\colorbox{yellow}{$x = 4$}Cancelled term in gray
LaTeX\frac{\textcolor{gray}{\cancel{x}}\,y}{\textcolor{gray}{\cancel{x}}} = y
In a LaTeX document
These commands work in the text of a .tex document (Overleaf, TeX Live, MiKTeX), not inside math. The box on the right shows what the compiled PDF looks like.
Colored words in text
LaTeX\usepackage{xcolor} ... This is \textcolor{red}{important}, and {\color{blue} this whole phrase is blue}.Compiled resultThis is important, and this whole phrase is blue.
Named and custom colors
xcolor knows basic names (red, green, blue, cyan, magenta, yellow, black, gray, white, darkgray, lightgray, brown, lime, olive, orange, pink, purple, teal, violet). Load it with [dvipsnames] for 68 more names such as ForestGreen and NavyBlue.
For brand or chart colors use \definecolor with HTML hex or RGB values, and mixes such as blue!30!white for lighter shades.
Color and readability
Readers who print in grayscale or have color vision deficiencies may not see the difference between red and green. Pair color with another cue (bold, a label, a pattern) and keep enough contrast against the background.
Common mistakes
Without xcolor (or color) the command is undefined.
Instead of\textcolor{red}{x} (no xcolor)Write\usepackage{xcolor}\colordoes not take the text as an argument; it colors everything after it in the group.Instead of\color{red}{this text}Write\textcolor{red}{this text}The HTML model takes the six hex digits without #.
Instead of\definecolor{brand}{HTML}{#1F6FEB}Write\definecolor{brand}{HTML}{1F6FEB}
In Overleaf, MathJax and Word
Overleaf and pdfLaTeX
xcolor is preinstalled; load it with
\usepackage{xcolor}(or[dvipsnames]for more names).MathJax and KaTeX
MathJax and KaTeX support
\color{red}{x}and\textcolor{red}{x}. Note that in MathJax\colortakes the text as an argument, unlike LaTeX.Microsoft Word
In Word select the text and use Home › Font Color; inside an equation the same button colors parts of the formula.
Already have the whole document?
Move complete papers between PDF, Word and LaTeX without retyping; every equation stays editable.
- PDF to LaTeXTurn a paper or textbook PDF into a .tex project with every equation.10 credits per page
- Word to LaTeXA .docx with Word equations becomes LaTeX ready for Overleaf.10 credits per page
- LaTeX to WordA whole .tex file becomes a .docx whose equations open in Word.5 credits per file
Single printed formulas are free: 3 a day without an account, 6 with a free account. New accounts get 30 credits to try handwriting, pages and documents; failed conversions return their credits. See plans and credit prices.
Text color in LaTeX: questions
- How do I change text color in LaTeX?
- Load xcolor and use
\textcolor{red}{text}. - How do I use a hex color?
\definecolor{name}{HTML}{1F6FEB}, then\textcolor{name}{…}.- How do I highlight text?
\colorbox{yellow}{text}, or the soul package's\hl{text}for highlights that break across lines.
Related LaTeX reference
- How to Bold in LaTeX\textbf for bold text, \mathbf for upright bold math, \boldsymbol or \bm for bold italic and Greek symbols.
- How to Change Font Size in LaTeXDocument size (10/11/12pt), the ten size commands with point values, exact sizes with \fontsize, and math sizes.
- LaTeX Underline: Text and Math\underline for short text and formulas, ulem's \uline and soul's \ul for text that breaks across lines, plus double and wavy lines.
- How to Write Code in LaTeXInline code with \verb, code blocks with verbatim, listings and minted, line numbers, colors and code from files.
- How to Add a Footnote in LaTeX\footnote basics, symbol marks, footnotes in tables and minipages, and notes on equations.
- Quotation Marks in LaTeXOpening and closing quotes with backquotes and apostrophes, csquotes \enquote, block quotations and quotes in math.
- LaTeX equation editorSymbol panel, live preview, and PNG, SVG, MathML or Word export.
- All LaTeX reference pagesSymbols, math structures and text formatting in one list.
Have the formula as a picture?
Paste a screenshot or photo of the equation and get its LaTeX, ready to copy or open in the editor.
Convert an image to LaTeX