Skip to main content
To change text color in LaTeX, load \usepackage{xcolor} and write \textcolor{color}{text} for inline text or \colorbox{color}{text} for a colored background. This guide covers text color, font size commands (\tiny through \Huge and \fontsize), and paragraph alignment; for bold, italics, emphasis, and underlining, see Bold, italics, and underlining.

Text color and background boxes (xcolor)

Load \usepackage{xcolor} in the preamble to enable color commands. Use \textcolor{color}{text} for a short phrase, {\color{color} ...} when changing color across several paragraphs, \colorbox{bg}{text} for a shaded box, and \fcolorbox{border}{bg}{text} for a bordered colored box. xcolor defines 19 base color names out of the box: red, green, blue, cyan, magenta, yellow, black, darkgray, gray, lightgray, white, brown, lime, olive, orange, pink, purple, teal, and violet. Pass [dvipsnames] or [svgnames] to \usepackage for wider named palettes, or mix any two colors inline with colorA!percent!colorB (for example blue!70!black mixes 70% blue with 30% black; yellow!25 mixes 25% yellow with 75% white).
text-color.tex
Ready to use this syntax? Continue in the browser editor when you want to adapt the example in a real project.Open LaTeX Cloud Studio
Define reusable custom colors in the preamble with \definecolor{name}{model}{spec}: If you use a color name that has not been loaded or defined, LaTeX stops with ! Package xcolor Error: Undefined color `...'..

Font size commands (\tiny to \Huge)

Standard LaTeX classes (article, report, book) provide ten relative size declarations. Unlike \textcolor{...}{...}, size commands are switches rather than commands that take an argument: wrap them in braces ({\large text}) or an environment (\begin{small} ... \end{small}) to limit their scope.
font-sizes.tex
The exact point size and baseline skip of each command depend on the document class option (10pt, 11pt, or 12pt). In size10.clo, size11.clo, and size12.clo: At 12pt, \Huge is defined identically to \huge (24.88pt).

Exact sizes with \fontsize

To set an arbitrary size, call \fontsize{size}{baselineskip}\selectfont (a typical baseline skip is roughly 1.2 times the font size). Two details matter when using \fontsize:
  1. Use a scalable font such as \usepackage{lmodern} (Latin Modern). Default Computer Modern provides only fixed discrete sizes and substitutes the nearest match with LaTeX Font Warning: Font shape `OT1/cmr/m/n' in size <15> not available.
  2. End the paragraph inside the group (with a blank line or \par before }). TeX applies the baseline skip that is active when the paragraph ends; closing the group before \par leaves large text squeezed onto the surrounding \normalsize line spacing.
custom-fontsize.tex

Text alignment

LaTeX justifies body paragraphs on both margins by default. To align text left, center, or right, choose between an environment (adds vertical space above and below) and a declaration (adds no vertical space, preferred inside figure, table, or minipage): Just as with font size switches, when you scope \centering, \raggedright, or \raggedleft inside {...}, include a blank line or \par before the closing brace so TeX breaks the paragraph under that alignment.
text-alignment.tex

Try it in the editor

xcolor and lmodern are installed in LaTeX Cloud Studio’s TeX Live 2026 (full distribution) environment. Start from the Basic Article template in LaTeX Cloud Studio and replace main.tex with the complete example.