I am just trying to get a rounded corner box with some text in it. The text color will be white and the box will be filled with a particular color.

The preamble includes:


The code I have used is:

\node[drop shadow,fill=black,draw,rounded corners]

How can I specify an arbitrary color (RGB values in a range of 0-255) in the fill option?

Also, am I using too advanced a tool (tikz) to do something simple (draw a rounded corner rectangle filled with a color and text of some other color)?

  • 3
    The HTML format is quite helpful, too: \definecolor{orange}{HTML}{FF7F00} (see my blog post for examples) Commented Apr 8, 2017 at 19:28

4 Answers 4


In answer to your first question - mixing colours in (say) RGB format - you could use the notation similar to that specified in the xcolor package documentation, since TikZ recognizes this. For example, mixing/sharing proportions of black green is obtained using


and displays

Nodes with different colour fills (sharing between black and green)

Or, if you're interested in mixing certain quantities of RGB colours, you can use a part-wise mix as follows:


which outputs

Part-wise mix of colours

For answering your second question - dealing with boxes - you can use the fancybox package or even PStricks. Here is an example using the latter:


PStricks rounded/coloured boxes

  • 9
    Cool, I didn't know before about the rgb:... syntax!
    – Daniel
    Commented Jul 2, 2012 at 21:24
  • 3
    About the notation rgb:red,4;green,2;yellow,1, what are the units? Seems not to be percentage...
    – kebs
    Commented Dec 11, 2017 at 14:24
  • 1
    @kebs: I think the units are all converted to shares of the total (red + green + yellow; perhaps within some range, either [0,1] or [0,255]), since this code produces the same output for all \psframeboxs.
    – Werner
    Commented Dec 12, 2017 at 16:29
  • 4
    Hmmmm... suspicious. {rgb:red,1;green,1:blue,1} seems to be some kind of subtractive mixing since I get an ugly brown and not white.
    – Jason S
    Commented Sep 28, 2020 at 20:59
  • 1
    @JasonS Well, each of the three values is divided by the sum of all values, so you get .333,.333,.333 in "standard" notation which is some darker gray. If you specify the divisor explicitly using {rgb,1:red,1;green,1:blue,1} you would get white. Commented Aug 11, 2022 at 11:48

One approach is to predefine in the preamble all colors one wants to use, for instance


with values in the interval (0,1) or


with integer values in the range 0–255 (use a more sensible name than mycolor) and then mycolor can be used in all color specifications, for instance

\node[drop shadow,fill=mycolor,draw,rounded corners]

In this way you can control the colors and also change them just by modifying their definition.

  • It is also possible to define the colors right before you use them. You can even redefine them later if you want to use different values for them. I did that once when I was generating a plot with a lot of different colors in it. I have created a new answer for this alternative approach. Commented Aug 4, 2012 at 0:38
  • @StrawberryFieldsForever I don't think that changing the meaning of a color name is a good way to proceed.
    – egreg
    Commented Aug 4, 2012 at 11:08
  • 1
    Why not? It will be like any other variable. Of course you shouldn't call the color "red" or something like that if you intend to change its value because you would expect that color to be constant, but if you call it "mycolor" or "tempcolor" I see no problem with it. Commented Aug 4, 2012 at 15:07
  • 2
    Notably this requires you to \usepackage{xcolor}
    – Migwell
    Commented May 27, 2021 at 14:27

Werner has shown the rgb-syntax to mix colors, egreg has shown how to define a color in RGB and then use it. If you want to specify a color with RGB values [0-255] without defining it before, you can use the rgb-syntax Werner has shown by setting the optional div-parameter to 255 (see xcolor package documentation, pages 13 and 16).

\tikz\node[rounded corners, fill={rgb,255:red,21; green,66; blue,128}, text=white, draw=black] {hello world};

Another approach, that builds on egregs answer, is to predefine the color one wants to use right before it is used. In that way one doesn't have to be so creative when coming up with the names for all colors, which is especially cumbersome if a lot of different colors have to be defined. The color can then be used in all color specifications (just like colors defined in the preamble), for instance

\node[drop shadow,fill=tempcolor,draw,rounded corners]

with values in the interval (0,1) or

\node[drop shadow,fill=tempcolor,draw,rounded corners]

with integer values in the range 0–255 (the name "tempcolor" is just a suggestion).

If you want to make sure you're not overriding any earlier defined color named tempcolor, you can always define the color in a separate scope:

    \node[drop shadow,fill=tempcolor,draw,rounded corners]

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .