Using RGBA values, creates colors for using in the background, shapes, lines and points.

Explore the 256^3 possible colors you can choose from using three numeric parameters.

Note that if only one parameter is provided to rgb(), it will be interpreted as a grayscale value. Add a second parameter, and it will be used for alpha transparency for grayscale. When three parameters are specified, they are interpreted as RGB values. Adding a fourth parameter applies alpha transparency to the RGB color.


Flag of France

You can look up official RGB values for most country flags on Wikipedia.

// You can look up official RGB values for most country flags on Wikipedia.
rect(50, 50, 300, 100);

rect(50, 150, 300, 100);

rect(50, 250, 300, 100);

// one parameter is grayscale
rect(100, 100, 50, 50);

// two parameters is grayscale and transparency
rect(150, 100, 50, 50);

// three parameters are RGB values
rect(100, 150, 50, 50);

// four parameters are RGB values and transparency
fill(rgb(0, 100, 200, 1));
rect(150, 150, 50, 50);


rgb(r, g, b, a)


r Number The amount of red (0-255) in the color, or if the only parameter a grayscale value.
g Number The amount of green (0-255) in the color, or if the last parameter the alpha transparency for grayscale
b Number The amount of blue (0-255) in the color.
a Number The alpha transparency, a number between 0 (fully transparent) and 1(fully opaque), of the color. Default is 1.


Returns a color. Usually used as a parameter to background(), fill(), or stroke().


  • If any of the RGBA values is out of range (0-255), then the value is rounded into range. For example, 300 becomes 255 and -100 becomes 0.

Found a bug in the documentation? Let us know at documentation@code.org