Use CSS-style color specifications in xcolor?
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.
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:
\textcolor[HTML]{AFFE90}{foo}
(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:
\documentclass[a4paper]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\definecolor{foo}{HTML}{EFF5F9}
\definecolor{magenta}{HTML}{FF00FF}
\begin{document}
This is the \textcolor{foo}{foo color}. And here is an
\textcolor[HTML]{DFECF7}{inline example}.
I like \textcolor{magenta}{\textbf{Magenta}}.
\end{document}
which renders to
IMPORTANT The letters in the HTML color code have to be upper case.