I have colors on my website #eff5f9 and #dfecf7. I would like to also use them in a latex document. Is there a way to use such hexadecimal specifications with xcolor?

I've tried to read the xcolor manual, and I'm fairly convinced it was written to be as unhelpful as possible. Googling does not reveal any simple xcolor tutorials.


3 Answers 3


According to http://en.wikibooks.org/wiki/LaTeX/Colors#Color_Models you can simply use \definecolor{orange}{HTML}{FF7F00} to define colors using a CSS-style hexadecimal notation. If you simply want to use a CSS-style color instead of defining a new named one, you can use \color[HTML]{FF7F00}.

Also, for solutions using the HTML color encoding to work, you must include the xcolor package.

  • 1
    @Marcin: Check your browser and internet connection. I just loaded that page with no problems. May 11, 2011 at 20:13
  • 19
    please note that you have to use big letters. So \definecolor{orange}{HTML}{ff7f00} will not work, \definecolor{orange}{HTML}{FF7F00} will work. And you have to include \usepackage{xcolor}. Aug 6, 2012 at 7:07

Section 2.2 of the xcolor manual lists the various available colour models. One of them is called HTML and it says:

HTML This is a model derived from rgb in order to enable input of color parameters from web pages or CSS files. Therefore, it is not really a color model of its own right, but rather a user interface for convenience. It is worth mentioning that HTML accepts any combination of the characters 0–9, A–F, a–f, as long as the string has a length of exactly 6 characters. However, outputs of conversions to HTML will always consist of numbers and uppercase letters.

This means that whenever an xcolor command allows you to specify a colour model, you can put HTML in for the model to use the HTML syntax. An example is given near the start of Section 2.2:


(As I typed this, Jannis posted an answer explaining how to do this with the \definecolor command.)

Of course, the colours in your document might not be exactly the same as those on your webpage, but that's due more to the complexity of colour than the xcolor package. Take a look at PDF colour model and LaTeX for more on this.


A complete minimal example:




    This is the \textcolor{foo}{foo color}. And here is an
    \textcolor[HTML]{DFECF7}{inline example}.

    I like \textcolor{magenta}{\textbf{Magenta}}.

which renders to

enter image description here

IMPORTANT The letters in the HTML color code have to be upper case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.