Background color in LaTeX can mean the color of the page, a highlight behind a few words, a shaded table row, or a box around a paragraph. They all start with the xcolor package.
Short answer
Load xcolor. Use \pagecolor{...} for the page, \colorbox{yellow}{text} behind text, \cellcolor and \rowcolor in tables (load xcolor with the table option), and a tcolorbox for shaded paragraphs.
Page background
\documentclass{article}
\usepackage{xcolor}
\definecolor{paleblue}{RGB}{230,240,255}
\begin{document}
\pagecolor{paleblue}
This page has a pale blue background.
\newpage
\nopagecolor
This page is white again.
\end{document}\pagecolor applies from the current page on; \nopagecolor switches it off. Colors can be named (red, gray), defined with \definecolor in RGB, HTML or CMYK, or mixed: blue!10 is 10% blue and 90% white, and red!50!black is a dark red.
Highlight text
\documentclass{article}
\usepackage{xcolor}
\begin{document}
Some \colorbox{yellow}{highlighted text},
\fcolorbox{red}{yellow!30}{a framed box},
and \textcolor{red}{red text}.
\end{document}\colorbox cannot break across lines. For highlighting that wraps, use the soul package with \hl{...}, or lua-ul if you compile with LuaLaTeX.
Table rows and cells
Load xcolor with the table option (it must be the first time xcolor is loaded, or pass the option with \PassOptionsToPackage before the class). Then \rowcolor shades a row, \cellcolor a cell, and \rowcolors alternates colors automatically:
\documentclass{article}
\usepackage[table]{xcolor}
\begin{document}
\begin{tabular}{ll}
\rowcolor{gray!25} Group & Mean \\
A & \cellcolor{green!20} 3.2 \\
B & 4.1 \\
\end{tabular}
\bigskip
\rowcolors{2}{gray!10}{white}
\begin{tabular}{ll}
A & 1 \\
B & 2 \\
C & 3 \\
\end{tabular}
\end{document}\rowcolors{2}{gray!10}{white} starts at row 2 and alternates the two colors. Many journals print tables in black and white, so check the author guidelines before shading a submitted table.
A colored box around a paragraph
tcolorbox gives a box with a background, frame and optional title, and it can break across pages with the breakable library:
\documentclass{article}
\usepackage{tcolorbox}
\begin{document}
\begin{tcolorbox}[colback=yellow!10, colframe=orange!80!black, title=Note]
A shaded paragraph with an orange frame and a title.
\end{tcolorbox}
\end{document}Code listings
With the listings package, set the background in \lstset:
\documentclass{article}
\usepackage{xcolor}
\usepackage{listings}
\lstset{backgroundcolor=\color{gray!10}, basicstyle=\ttfamily\small}
\begin{document}
\begin{lstlisting}
print("hello")
\end{lstlisting}
\end{document}A watermark or background image
The eso-pic package draws behind every page, which is how you add a DRAFT watermark or a background image:
\documentclass{article}
\usepackage{xcolor}
\usepackage{graphicx}
\usepackage{eso-pic}
\AddToShipoutPictureBG{%
\AtPageCenter{\makebox[0pt]{\rotatebox{45}{%
\scalebox{6}{\textcolor{gray!20}{DRAFT}}}}}}
\begin{document}
Text above the watermark.
\end{document}For a full-page image, replace the text with \includegraphics[width=\paperwidth,height=\paperheight]{file} and use \AddToShipoutPictureBG with \AtPageLowerLeft. In Beamer slides, use \setbeamercolor{background canvas}{bg=blue!5} instead.
Frequently Asked Questions
How do I change the background color of a page in LaTeX?
Load xcolor and use \pagecolor{colorname}. Use \nopagecolor to go back to white.
How do I color a table cell in LaTeX?
Load \usepackage[table]{xcolor} and put \cellcolor{color} at the start of the cell, or \rowcolor{color} at the start of a row.
How do I highlight text in LaTeX?
Use \colorbox{yellow}{text} from xcolor for short phrases, or \hl{text} from the soul package for highlighting that wraps across lines.
More LaTeX Guides
Written by Dr. Meng Zhao
Physician-Scientist · Founder, LabCat AI
MD · Former Neurosurgeon · Medical AI Researcher
Dr. Meng Zhao is a former neurosurgeon turned medical-AI researcher. After years in the operating room, he moved into applied AI for clinical workflows and now leads LabCat AI, a medical-AI company working on decision support and research tooling for clinicians. He built Journal Metrics as a free resource for researchers who need reliable journal metrics without paid database subscriptions.
Related Articles
LaTeX Page Numbering: Roman Numerals, Page X of Y, and Removing Page Numbers
How to change page numbering in LaTeX: switch between roman and arabic numerals, start at any number, move the number, show "Page X of Y", and remove the number from the title page.
7 min readLaTeXLaTeX Footnotes: Add, Reuse and Customize Footnotes (Including in Tables)
How to use footnotes in LaTeX: \footnote, footnotes in tables and minipages, referring to the same footnote twice, symbols instead of numbers, unnumbered notes and endnotes.
7 min readLaTeXLaTeX Hyperlinks with hyperref: \href, \url, Link Colors and Internal Links
How to add hyperlinks in LaTeX with hyperref: \href and \url, email links, links to sections and pages, colored links instead of boxes, breaking long URLs, and PDF metadata.
7 min read