TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 23 down vote accepted

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.

share|improve this answer
Thanks. Incidentally, that page won't load for me. FML. – Marcin May 11 '11 at 20:11
@Marcin: Check your browser and internet connection. I just loaded that page with no problems. – Loop Space May 11 '11 at 20:13
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}. – Martin Thoma Aug 6 '12 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.

share|improve this answer

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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