In CSS, you can define colors using hexadecimal values in the format:
#rrggbb
Where RR (red), GG (green), and BB (blue) are represented by hexadecimal values ranging from 00 to FF (equivalent to decimal 0-255).
For instance, #FF0000 corresponds to red, as red is at its maximum value (FF) while green and blue are at their minimum (00).
To represent black, all values are set to 00, like so: #000000.
Similarly, to represent white, all values are set to FF, as in: #FFFFFF.
You can experiment with different combinations of these HEX values to create various colors.
Example
Gray shades are frequently achieved by setting equal values for all three light sources.
Occasionally, you might encounter a 3-digit hexadecimal code in CSS files.
This abbreviated code serves as a shorthand for certain 6-digit hexadecimal codes.
The 3-digit hexadecimal code follows this structure:
#rgb
Here, R, G, and B denote the red, green, and blue components, respectively, with values ranging from 0 to F.
This shortened format is applicable only when the values for all components (RR, GG, and BB) are identical.
For example, if we have #ff00CC, it could be represented as #f0C.
Here’s an illustration for better understanding:
Example
body { |