# Where to \definecolor?

When I put color definitions in the preamble, I get an error, e.g.

\documentclass[12pt]{article}

\usepackage{xcolor}

\definecolor{es-bg}{HTML}{e7edf4ff}% (cornflower light blue background at the top)
\definecolor{es-aqua}{HTML}{00ffffff}% (bright aquaish, matches)
\definecolor{es-lb}{HTML}{0090d4ff}% (lighter blue, matches)
\definecolor{es-db}{HTML}{003b74ff}% (darker blue, matches)

\begin{document}

\colorbox{es-aqua}{This should be a color.}

\end{document}


gives an error of "Missing \begin{document}".

If I put the definitions after \begin{document}, it compiles but there is an extra line "FFFFFFFF" in the document, e.g.

\documentclass[12pt]{article}

\usepackage{xcolor}

\begin{document}
\definecolor{es-bg}{HTML}{e7edf4ff}% (cornflower light blue background at the top)
\definecolor{es-aqua}{HTML}{00ffffff}% (bright aquaish, matches)
\definecolor{es-lb}{HTML}{0090d4ff}% (lighter blue, matches)
\definecolor{es-db}{HTML}{003b74ff}% (darker blue, matches)

\colorbox{es-aqua}{This should be a color.}

\end{document}


It's completely fine to define colors in the preamble. But the HTML format asks for 6 numbers/letters, not 8:

\documentclass[]{article}

\usepackage{xcolor}
\definecolor{es-bg}{HTML}{0df400}

\begin{document}
\textcolor{es-bg}{Hello}

\end{document}


The xcolor HTML color model takes 6 uppercase hex digits so

\documentclass[12pt]{article}

\usepackage{xcolor}

\definecolor{es-bg}{HTML}{E7EDF4}% (cornflower light blue background at the top)
\definecolor{es-aqua}{HTML}{00FFFF}% (bright aquaish, matches)
\definecolor{es-lb}{HTML}{0090D4}% (lighter blue, matches)
\definecolor{es-db}{HTML}{003B74}% (darker blue, matches)

\begin{document}

\colorbox{es-aqua}{This should be a color.}

\end{document}

• Thanks! (I selected the other answer because it was slightly ahead of you and the poster doesn't have 626k karma, however you answer indicates that the trailing ff is the problem in the colors).
– yoyo
Sep 17 at 19:12