0 added
0 removed
Original
2026-01-01
Modified
2026-03-09
1
<p>Recall that the color of the text and background can be controlled using the color and background-color properties.</p>
1
<p>Recall that the color of the text and background can be controlled using the color and background-color properties.</p>
2
<p>Now let’s take a detailed look at the values of these properties.</p>
2
<p>Now let’s take a detailed look at the values of these properties.</p>
3
<p>The color can be specified as a keyword (a full list of keywords is given in the<a>specification</a>). For example:</p>
3
<p>The color can be specified as a keyword (a full list of keywords is given in the<a>specification</a>). For example:</p>
4
color: black; /* Black */ color: red; /* Red */ color: white; /* White */<p>Another way to specify color is to indicate a <a>hexadecimal value</a>. This is what we used in the<a>previous assignment</a>. In this case, the color is formed from the<i>red</i>,<i>green</i>and<i>blue</i>components that are specified as a hexadecimal number that ranges from 00 to ff. In addition to the six-character hexadecimal format, the color code may also consist of a three-character triplet. In this case, the second character in the color components is duplicated first:</p>
4
color: black; /* Black */ color: red; /* Red */ color: white; /* White */<p>Another way to specify color is to indicate a <a>hexadecimal value</a>. This is what we used in the<a>previous assignment</a>. In this case, the color is formed from the<i>red</i>,<i>green</i>and<i>blue</i>components that are specified as a hexadecimal number that ranges from 00 to ff. In addition to the six-character hexadecimal format, the color code may also consist of a three-character triplet. In this case, the second character in the color components is duplicated first:</p>
5
color: #000; /* Black, the same as #000000 */ color: #f00; /* Red, the same as #ff0000 */ color: #fff; /* White, the same as #ffffff */<p>If you do not want to deal with hexadecimal values, you can use the special rgb function, which specifies the color in a more familiar decimal format within the range of 0 to 255. This code also consists of three color components that are separated by commas:</p>
5
color: #000; /* Black, the same as #000000 */ color: #f00; /* Red, the same as #ff0000 */ color: #fff; /* White, the same as #ffffff */<p>If you do not want to deal with hexadecimal values, you can use the special rgb function, which specifies the color in a more familiar decimal format within the range of 0 to 255. This code also consists of three color components that are separated by commas:</p>
6
color: rgb(0, 0, 0) /* Black, which is the same as #000000 */ color: rgb(255, 0, 0) /* Red, which is the same as #ff0000 */ color: rgb(255, 255, 255) /* White, which is the same as #ffffff */<p>The rgb function has an extended version: rgba. In this case, the code not only specifies the color: the last value in the code indicates the degree of opacity of the color, which is also known as its alpha. The value may vary from 0 (fully transparent) to 1 (fully opaque):</p>
6
color: rgb(0, 0, 0) /* Black, which is the same as #000000 */ color: rgb(255, 0, 0) /* Red, which is the same as #ff0000 */ color: rgb(255, 255, 255) /* White, which is the same as #ffffff */<p>The rgb function has an extended version: rgba. In this case, the code not only specifies the color: the last value in the code indicates the degree of opacity of the color, which is also known as its alpha. The value may vary from 0 (fully transparent) to 1 (fully opaque):</p>
7
color: rgba(0, 0, 0, 0.5) /* Black, 50% opaque */ color: rgb(255, 0, 0, 0.3) /* Red, 30% opaque */ color: rgb(255, 255, 255, 0.9) /* White, 90% opaque */
7
color: rgba(0, 0, 0, 0.5) /* Black, 50% opaque */ color: rgb(255, 0, 0, 0.3) /* Red, 30% opaque */ color: rgb(255, 255, 255, 0.9) /* White, 90% opaque */