O'Reilly logo

HTML5: Your visual blueprint™ for designing rich web pages and applications by Adam McDaniel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

USING SOLID COLOR ON THE CANVAS

You can customize what color is used when drawing on the canvas. Earlier sections of this chapter have shown shapes, paths, and text drawn in black, which is the default if the fillStyle and strokeStyle attributes are undefined.

context.fillStyle = 'color';context.strokeStyle = 'color';

The color value can be one of four string formats:

  • #RRGGBB — Specifies an RGB color in three pairs of hexadecimal numbers, from 00 for no color to FF for maximum color, depending on position. For example, #FF8000 is maximum red, half green, and no blue, which appears orange.
  • rgb(rrr, bbb, ggg) — Specifies an RGB color, very similar to #RRGGBB, except the values are decimal numbers from 0 to 255. For example, rgb(255, 128, 0) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required