Colored Boxes in LaTeX: tcolorbox Complete Guide

Date Published

Colored Boxes in LaTeX: tcolorbox Complete Guide

Colored Boxes in LaTeX with tcolorbox

The tcolorbox package creates beautiful, customizable boxes for callouts, theorems, and highlights. It is the right tool for anything with a colored background, a title bar or a shadow. But LaTeX also ships with a family of plain box commands, \fbox, \framebox, \fcolorbox and \parbox, that need no package at all and cover simple frames, empty boxes for forms, and boxed equations. This guide starts with those, then covers tcolorbox in depth, and finishes with boxes in Beamer slides.

Quick answer: How do you make a colored box in LaTeX? Load \usepackage[most]{tcolorbox} and wrap the text in \begin{tcolorbox}[colback=blue!5, colframe=blue!60!black, title=Note] ... \end{tcolorbox}. colback sets the box color, colframe the frame color, and enhanced, drop shadow adds a shadow.

No package? For a one-line color box, \colorbox{yellow!30}{text} or \fcolorbox{red}{yellow!20}{text} from xcolor is enough.

LaTeX Color Box Cheat Sheet (Copy and Paste)

The most-used colored box styles in one document you can paste and compile. \usepackage[most]{tcolorbox} loads xcolor and the skins and breakable libraries for you. Use the copy button on the box:

1\documentclass{article}
2\usepackage[most]{tcolorbox} % loads xcolor + skins, breakable, theorems
3\begin{document}
4% 1. Basic color box: colback = fill, colframe = border
5\begin{tcolorbox}[colback=blue!5, colframe=blue!60!black]
6 A light blue box with a dark blue frame.
7\end{tcolorbox}
8% 2. Colored box with a title bar
9\begin{tcolorbox}[colback=green!5, colframe=green!50!black, title=Tip]
10 Content under a green title bar.
11\end{tcolorbox}
12% 3. Drop shadow (needs enhanced)
13\begin{tcolorbox}[enhanced, drop shadow, colback=white, colframe=black!60]
14 A box with a shadow.
15\end{tcolorbox}
16% 4. Fuzzy shadow, rounded corners, no frame line
17\begin{tcolorbox}[enhanced, drop fuzzy shadow, arc=4mm, frame hidden, colback=yellow!10]
18 Soft shadow and rounded corners.
19\end{tcolorbox}
20% 5. Box that can break across pages
21\begin{tcolorbox}[breakable, colback=gray!10, colframe=gray!60]
22 Long content that may continue on the next page.
23\end{tcolorbox}
24% 6. Inline color boxes: xcolor commands and \tcbox
25\colorbox{yellow!30}{highlighted} \fcolorbox{red}{yellow!20}{framed and filled}
26\tcbox[on line, colback=red!10, colframe=red]{inline tcbox}
27\end{document}

Try this in Octree — free LaTeX editor with AI, compiles in your browser

Plain Boxes: \fbox, \framebox, \fcolorbox and \parbox

\fbox: a frame around anything

\fbox{text} draws a rectangular frame around its argument, which can be text, an image or a formula:

\fbox{This is framed.}

\fbox{\includegraphics[width=4cm]{figure.png}}

The frame hugs the content. Two lengths control its look: \fboxsep is the padding between content and frame (default 3pt) and \fboxrule is the line thickness (default 0.4pt). Change them globally in the preamble or locally inside a group:

{\setlength{\fboxsep}{6pt}\setlength{\fboxrule}{2pt}\fbox{thick, padded frame}}

\framebox: a frame with a fixed width

\framebox[width][pos]{text} works like \fbox but lets you set the width and the alignment of the content inside it. The position is c (centered, the default), l, r, or s to stretch the content across the box:

\framebox[4cm][l]{left aligned}

\framebox[4cm][r]{right aligned}

\framebox[4cm]{centered}

Both \fbox and \framebox produce a single line: the content will not wrap. For multi-line boxes see \parbox below.

\fcolorbox and \colorbox: color the frame and the fill

Load xcolor and you get two colored cousins. \colorbox{color}{text} fills the background with no frame, and \fcolorbox{frame color}{fill color}{text} draws a colored frame around a colored background:

\usepackage{xcolor}

\colorbox{blue!15}{highlighted text}

\fcolorbox{red}{yellow!20}{framed and filled}

The ! syntax mixes a color with white: blue!15 is 15% blue. Both commands respect \fboxsep and \fboxrule, so a frameless highlight with tight padding is {\setlength{\fboxsep}{1pt}\colorbox{yellow}{word}}.

Multi-line boxes with \parbox and minipage

To frame a paragraph, put a \parbox or a minipage inside the frame. \parbox[pos]{width}{text} is for plain text; minipage is for anything that needs its own paragraphs, lists or footnotes:

\fcolorbox{blue}{white}{\parbox{0.5\linewidth}{Several lines of text that wrap inside a colored frame.}}

\fbox{\begin{minipage}{0.8\linewidth} A paragraph inside a frame with a list: \begin{itemize}\item one \item two\end{itemize} \end{minipage}}

The optional position (t, c or b) sets which line of the box aligns with the surrounding baseline. A frame the exact width of the text column needs the padding and rule subtracted from the inner width:

\fcolorbox{black}{gray!10}{\parbox{\dimexpr\linewidth-2\fboxsep-2\fboxrule}{Full-width framed paragraph.}}

Empty boxes for forms and checklists

An empty box is just a frame around an invisible rule. The usual tricks:

\framebox[2cm]{\strut} — a 2cm wide box one line tall, good for a short blank in a form

\fbox{\rule{0pt}{1cm}\rule{3cm}{0pt}} — a 3cm by 1cm empty box; the first rule gives height, the second gives width

Name: \framebox[5cm]{\strut} — an inline fill-in field

\framebox[3cm][l]{\rule{0pt}{2em}} — a taller blank

For checkboxes, use a math symbol. \square and \Box from amssymb give an empty box; \blacksquare a filled one:

$\square$ Option A \quad $\Box$ Option B

The wasysym package has text-mode checkboxes including a ticked and a crossed version:

\usepackage{wasysym}

\Square\ Not done \quad \CheckedBox\ Done \quad \XBox\ Rejected

Boxes around images and tables

\fbox accepts any box, so the same command frames a picture or a whole table. For an image, set \fboxsep to zero if you want the rule to touch the edge of the picture:

{\setlength{\fboxsep}{0pt}\fbox{\includegraphics[width=5cm]{photo.jpg}}}

\fbox{\begin{tabular}{ll} Name & Value \\ A & 1 \end{tabular}}

A frame around a table is a quick alternative to drawing every rule with \hline and | column separators, and the same \fcolorbox trick gives it a tinted background.

\boxed for equations and \mbox

In math mode, \boxed{...} from amsmath frames a formula, which is the standard way to highlight a final result:

\[ \boxed{x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}} \]

\mbox{...} is the frameless relative of \fbox: it keeps its content on one line and prevents a line break inside it. \makebox[width][pos]{...} is the frameless \framebox. Both are useful for spacing and alignment when you do not want a visible rule.

Getting Started with tcolorbox

\usepackage{tcolorbox}

For more features:

\tcbuselibrary{skins, breakable, theorems}

Or load everything at once with \usepackage[most]{tcolorbox}.

Basic Box

\begin{tcolorbox} This is a basic colored box. \end{tcolorbox}

Box with Title

\begin{tcolorbox}[title=My Title] Content goes here. \end{tcolorbox}

Box Color in LaTeX: Background, Frame and Title Colors

Colors use xcolor syntax: blue!10 is 10% blue mixed with white, red!50!black is red darkened with black. The base names (red, green, blue, cyan, magenta, yellow, orange, purple, teal, gray, black, white and a few more) always work; for names like NavyBlue load \usepackage[dvipsnames]{xcolor} before tcolorbox, or define your own with \definecolor{brand}{RGB}{0,82,155}.

Background Color

\begin{tcolorbox}[colback=blue!10] Light blue background. \end{tcolorbox}

Frame Color

\begin{tcolorbox}[colframe=red] Red frame. \end{tcolorbox}

Title Colors

\begin{tcolorbox}[ title=Title, colbacktitle=green!50, coltitle=black ] Content. \end{tcolorbox}

Shadows

Shadows require the skins library and the enhanced skin.

Drop Shadow

\begin{tcolorbox}[enhanced, drop shadow] Box with shadow. \end{tcolorbox}

Shadow Options

drop shadow accepts a color, and the general shadow key sets the horizontal shift, vertical shift, corner offset and color by hand:

\begin{tcolorbox}[ enhanced, drop shadow=black!50!white ] Lighter shadow. \end{tcolorbox}

\begin{tcolorbox}[ enhanced, shadow={2mm}{-2mm}{0mm}{black!50!white} ] Customized shadow. \end{tcolorbox}

Directional presets such as drop shadow southeast and drop lifted shadow are also available.

Fuzzy Shadow

\begin{tcolorbox}[enhanced, drop fuzzy shadow] Soft blurred shadow. \end{tcolorbox}

Give it a color with drop fuzzy shadow=blue!50!black.

Box Styles

Rounded Corners

\begin{tcolorbox}[arc=4mm] Rounded corners. \end{tcolorbox}

Sharp Corners

\begin{tcolorbox}[sharp corners] Sharp corners. \end{tcolorbox}

No Frame

\begin{tcolorbox}[enhanced, frame hidden] No visible frame. \end{tcolorbox}

Fixed Width

\begin{tcolorbox}[width=6cm, halign=center] Narrow centered box. \end{tcolorbox}

Theorem-like Boxes

Create numbered theorems:

\newtcbtheorem{theorem}{Theorem}{colback=blue!5, colframe=blue!50}{th}

\begin{theorem}{Pythagorean}{pyth} In a right triangle, $a^2 + b^2 = c^2$. \end{theorem}

The last argument is a label prefix, so this theorem can be referenced with \ref{th:pyth}.

Breakable Boxes

For boxes that span pages:

\begin{tcolorbox}[breakable] Long content that may span multiple pages. \end{tcolorbox}

Predefined Styles

Warning Box

\begin{tcolorbox}[ colback=yellow!10, colframe=orange, title=Warning ] Warning message. \end{tcolorbox}

Info Box

\begin{tcolorbox}[ colback=blue!5, colframe=blue!50, title=Note ] Informational note. \end{tcolorbox}

Success Box

\begin{tcolorbox}[ colback=green!5, colframe=green!50, title=Success ] Success message. \end{tcolorbox}

Error Box

\begin{tcolorbox}[ colback=red!5, colframe=red!50, title=Error ] Error message. \end{tcolorbox}

Custom Styles

Define reusable styles:

\tcbset{mystyle/.style={ colback=gray!10, colframe=gray!50, fonttitle=\bfseries, arc=2mm, enhanced, drop shadow }}

\begin{tcolorbox}[mystyle, title=Custom] Using the custom style. \end{tcolorbox}

Sidebars and Margins

Left Bar

\begin{tcolorbox}[ blanker, borderline west={3pt}{0pt}{blue} ] Box with left border only. \end{tcolorbox}

Inline Boxes

\tcbox{inline box} — small inline colored box

Options go in square brackets, and on line keeps the box on the text baseline:

\tcbox[on line, size=small, colback=red!10, colframe=red]{inline}

Boxes in Beamer

Beamer has its own box environments, and tcolorbox works on slides as well.

block, alertblock and exampleblock

Every Beamer theme defines three colored blocks with a title bar:

\begin{frame}{Boxes in Beamer} \begin{block}{Definition} A block is Beamer's built-in colored box. \end{block} \begin{alertblock}{Warning} Red by default in most themes. \end{alertblock} \begin{exampleblock}{Example} Green by default. \end{exampleblock} \end{frame}

Changing block colors

Set the title and body colors with \setbeamercolor. The alerted and example variants have their own keys:

\setbeamercolor{block title}{bg=blue!70, fg=white}

\setbeamercolor{block body}{bg=blue!10, fg=black}

\setbeamercolor{block title alerted}{bg=red!70, fg=white}

\setbeamercolor{block body alerted}{bg=red!10}

Rounded corners and a shadow for all blocks:

\setbeamertemplate{blocks}[rounded][shadow=true]

Underneath, blocks are built from beamercolorbox, which you can use directly for a one-off colored panel:

\begin{beamercolorbox}[sep=1em, rounded=true, shadow=true]{block body} A raw beamercolorbox. \end{beamercolorbox}

tcolorbox inside Beamer

Load the package as usual in a Beamer document. The beamer skin makes a tcolorbox match the slide's rounded, shadowed style, and every other option in this guide works on a frame:

\documentclass{beamer} \usepackage[most]{tcolorbox}

\begin{frame}{tcolorbox on a slide} \begin{tcolorbox}[beamer, title=Key result, colback=blue!5, colframe=blue!60] tcolorbox works inside Beamer frames. \end{tcolorbox} \begin{tcolorbox}[enhanced, colback=yellow!10, colframe=orange, title=Note] Standard options work too. \end{tcolorbox} \end{frame}

Use tcolorbox in Beamer when you need a color scheme that differs from the theme, a box without a title bar, or a breakable box across allowframebreaks frames; stick with block when you want the slides to stay consistent with the theme.

Common tcolorbox Errors and Fixes

"Environment tcolorbox undefined"

Cause: the package is not loaded. Fix: add \usepackage{tcolorbox} (or \usepackage[most]{tcolorbox}) to the preamble, before \begin{document}.

"I do not know the key '/tcb/drop shadow'"

Cause: shadow, enhanced and other skin keys live in the skins library; breakable and theorems have libraries of their own. Fix: load \usepackage[most]{tcolorbox} or \tcbuselibrary{skins, breakable}, and put enhanced in the options of any box with a shadow.

"Undefined color" (Package xcolor Error)

Cause: a color name xcolor does not know, such as NavyBlue or lightblue. Fix: load \usepackage[dvipsnames]{xcolor} before tcolorbox (loading it after with options gives an option clash), use a mix like blue!20, or define the color yourself:

1\documentclass{article}
2\usepackage[dvipsnames]{xcolor} % before tcolorbox, for names like NavyBlue
3\usepackage[most]{tcolorbox} % most = skins (shadows), breakable, theorems
4\definecolor{brand}{RGB}{0,82,155}
5\begin{document}
6\begin{tcolorbox}[enhanced, drop shadow, colback=NavyBlue!5, colframe=brand]
7 A shadow, a dvipsnames color and a custom RGB color.
8\end{tcolorbox}
9\end{document}

Quick Reference

Command or environment

Package

What it does

\fbox{text}

LaTeX core

frame that hugs the content

\framebox[4cm][l]{text}

LaTeX core

frame with fixed width and alignment

\mbox{text}, \makebox[4cm]{text}

LaTeX core

same boxes without a frame

\colorbox{color}{text}

xcolor

colored background, no frame

\fcolorbox{frame}{fill}{text}

xcolor

colored frame and background

\parbox{width}{text}, minipage

LaTeX core

multi-line content inside any frame

\framebox[2cm]{\strut}

LaTeX core

empty box for forms

$\square$, $\Box$

amssymb

empty checkbox symbol

\Square, \CheckedBox, \XBox

wasysym

text-mode checkboxes

\boxed{...}

amsmath

frame around a formula

tcolorbox environment

tcolorbox

colored box with title, shadow, skins

\tcbox{text}

tcolorbox

inline colored box

\newtcbtheorem

tcolorbox (theorems)

numbered theorem boxes

block, alertblock, exampleblock

beamer

themed boxes on slides

\setbeamercolor{block title}{...}

beamer

recolor Beamer blocks

Frequently Asked Questions

How do I put a box around text in LaTeX?

Use \fbox{text} for a plain frame, or \fcolorbox{black}{yellow!20}{text} for a colored one. For text that spans several lines, wrap it in \parbox{width}{...} or a minipage inside the frame, or switch to the tcolorbox environment, which wraps automatically.

How do I make an empty box in LaTeX?

\framebox[2cm]{\strut} gives an empty box one line tall and 2cm wide. For a custom size, frame two invisible rules: \fbox{\rule{0pt}{1cm}\rule{3cm}{0pt}} is 3cm wide and 1cm tall. For a checkbox symbol use $\square$ from amssymb.

What is the difference between \fbox and \framebox?

\fbox{text} sizes the frame to its content. \framebox[width][pos]{text} takes an explicit width and an alignment (l, r, c or s), which is what you need for blank fields, fixed-width labels and aligned columns of boxes. Without the optional arguments the two commands are identical.

How do I put a box around an equation?

Use \boxed{...} from amsmath inside math mode, for example \[ \boxed{E = mc^2} \]. It works inside align as well, boxing a single line. For a colored box around a displayed equation, put the equation inside a tcolorbox with colback set, or inside \fcolorbox with \parbox.

How do I change the thickness and padding of a frame?

Set \fboxrule for the line thickness and \fboxsep for the padding, for example \setlength{\fboxrule}{1pt} and \setlength{\fboxsep}{5pt}. In tcolorbox the equivalents are boxrule and boxsep, or the individual left, right, top and bottom keys.

How do I make a colored box in Beamer?

Use \begin{block}{Title} ... \end{block} and recolor it with \setbeamercolor{block title}{bg=..., fg=...} and \setbeamercolor{block body}{bg=...}. For full control, load tcolorbox and use \begin{tcolorbox}[beamer, colback=..., colframe=...] inside the frame.

Why does my tcolorbox shadow not appear?

Shadows need the skins library and the enhanced skin: write \usepackage[most]{tcolorbox} and add enhanced to the options, as in [enhanced, drop shadow].

How do I make a colored box in LaTeX?

Load \usepackage[most]{tcolorbox} and write \begin{tcolorbox}[colback=blue!5, colframe=blue!50] Text \end{tcolorbox}. For a short inline highlight, \colorbox{yellow!30}{text} from xcolor is enough.

How do I change the box color in LaTeX?

In tcolorbox set colback for the background, colframe for the frame, and colbacktitle and coltitle for the title bar. For \colorbox and \fcolorbox, the colors are the first arguments: \fcolorbox{frame}{fill}{text}.

How do I add a shadow to a tcolorbox?

Add enhanced, drop shadow to the options. drop fuzzy shadow gives a soft blurred shadow, drop shadow=black!50!white a lighter one, and shadow={2mm}{-2mm}{0mm}{black!50} sets the offset and color yourself. The skins library must be loaded.

Can a tcolorbox span multiple pages?

Yes. Load the breakable library (included in [most]) and add breakable to the options; the box then splits at a page break and continues on the next page.

Create Boxes with Octree

Octree simplifies tcolorbox:

  • Visual box builder
  • Preview styles instantly
  • AI suggests color schemes
  • Export polished documents

Try it at https://useoctree.com

Try this in Octree — free LaTeX editor with AI, compiles in your browser