3.14 RGB Values for Color

RGB stands for red, green, and blue. An RGB value specifies the amounts of red, green, and blue that mix together to form the displayed color. To specify an amount of a color, you can use a percentage, an integer, or a hexadecimal number (we’ll explain hexadecimal shortly). We’ll provide explanations and examples coming up, but for now, here are the allowable ranges for each technique:

  • percentage—0% to 100% for each color

  • integer—0 to 255 for each color

  • hexadecimal—00 to ff for each color

RGB Values with Percentages

To specify an RGB value with percentages, use this format:

rgb(red-percent, green-percent, blue-percent)

Each percent value must be between 0% and 100%. Here’s an example class selector rule that ...

Get Web Programming with HTML5, CSS, and JavaScript now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.