You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this example, the r, g, and b channels of the [=origin color=] are unchanged,
838
-
indicated by specifying them with the keywords
839
-
drawing their values from the [=origin color=],
840
-
but the opacity is set to ''80%'' to make it slightly transparent,
841
-
regardless of what the [=origin color's=] opacity was.
841
+
In this example, the specified percentages are resolved to numbers,
842
+
giving oklab(0.543 -0.09 -0.02).
843
+
The resulting RCS color has l = 1 - 0.543 = 0.457,
844
+
a = -0.09 * 0.8 = -0.072,
845
+
and b is unchanged at -0.02:
846
+
oklab(0.457 -0.072 -0.02).
842
847
</div>
843
848
849
+
If the [=origin color=] was originally specified with a different color function,
850
+
it's first converted into the chosen color function,
851
+
so it has meaningful values for the channels.
852
+
844
853
<div class=example>
845
854
By using the [=channel keywords=] in a [=math function=],
846
855
an [=origin color=] can be manipulated in more advanced ways.
@@ -862,6 +871,24 @@ so it has meaningful values for the channels.
862
871
due to being used in the ''lch()'' function.
863
872
</div>
864
873
874
+
<div class=example>
875
+
For example, if a theme color is specified as opaque,
876
+
but in a particular instance you need it to be partially transparent:
877
+
878
+
<pre highlight=css>
879
+
html { --bg-color: <span class="swatch" style="--color: blue"></span> blue; }
880
+
.overlay {
881
+
background: <span class="swatch" style="--color: rgb(0,0,255,80%)"></span> rgb(from var(--bg-color) r g b / 80%);
882
+
}
883
+
</pre>
884
+
885
+
In this example, the r, g, and b channels of the [=origin color=] are unchanged,
886
+
indicated by specifying them with the keywords
887
+
drawing their values from the [=origin color=],
888
+
but the opacity is set to ''80%'' to make it slightly transparent,
889
+
regardless of what the [=origin color's=] opacity was.
890
+
</div>
891
+
865
892
<div class=example>
866
893
While most uses of [=relative color=] syntax
867
894
will use the [=channel keywords=] in their corresponding argument,
@@ -877,12 +904,12 @@ so it has meaningful values for the channels.
877
904
</pre>
878
905
879
906
Using this,
880
-
''red'' would become ''rgb(30% 30% 30%)'',
881
-
''lime'' would become ''rgb(59% 59% 59%)'',
882
-
and ''blue'' would become ''rgb(11% 11% 11%)''.
907
+
''red'' would become ''rgb(76.5 76.5 76.5)'',
908
+
''lime'' would become ''rgb(150.45 150.45 150.45)'',
909
+
and ''blue'' would become ''rgb(150.45 150.45 150.45)''.
883
910
A more moderate color, like ''darkolivegreen'',
884
911
which has RGB values ''rgb(85 107 47)'',
885
-
would become approximately ''rgb(37% 37% 37%)''.
912
+
would become ''rgb(93.8 93.8 93.8)''.
886
913
887
914
(Rough because firstly,
888
915
although this looks like a luminance calculation,
@@ -919,11 +946,11 @@ Within a [=relative color=] syntax ''rgb()'' function,
919
946
the allowed [=channel keywords=] are:
920
947
921
948
* <dfn value for="rgb()">r</dfn>, <dfn value for="rgb()">g</dfn>, and <dfn value for="rgb()">b</dfn>
922
-
are all <<percentage>>s or<<number>>s
949
+
are all <<number>>s
923
950
that correspond to the [=origin color's=] red, green, and blue channels
924
-
after its conversion to sRGB. For <<number>>s, 255 (or 255.0)
925
-
is equivalent to 100%.
926
-
* <dfn value for="rgb()">alpha</dfn> is a <<number>>or <<percentage>>that corresponds to the [=origin color's=] alpha transparency
951
+
after its conversion to sRGB.
952
+
255.0 is equivalent to 100%.
953
+
* <dfn value for="rgb()">alpha</dfn> is a <<number>> that corresponds to the [=origin color's=] alpha transparency
927
954
928
955
<div class="example">
929
956
To manipulate color channels in the sRGB color space:
@@ -932,10 +959,12 @@ the allowed [=channel keywords=] are:
932
959
rgb(from <span class="swatch" style="--color: indianred"></span> indianred 255 g b)
933
960
</pre>
934
961
935
-
This takes the sRGB value of indianred (205 92 92) and replaces the red channel with 255 to give <span class="swatch" style="--color: rgb(255 92 92)"></span> rgb(255 92 92).
962
+
This takes the sRGB value of indianred (205 92 92) and replaces
Relative color syntax is only applicable to the non-legacy RGB syntactic forms.
967
+
Relative sRGB color syntax is <em>only</em> applicable to the non-legacy RGB syntactic forms.
939
968
940
969
<div class="example invalid">
941
970
For example, this attempt to use the rgba
@@ -980,9 +1009,10 @@ the allowed [=channel keywords=] are:
980
1009
after its conversion to sRGB,
981
1010
normalized to a [0deg, 360deg) range
982
1011
* <dfn value for="hsl()">s</dfn> and <dfn value for="hsl()">l</dfn>
983
-
are <<percentage>>s or <<number>>s that correspond to the [=origin color's=] HSL saturation and lightness
1012
+
are <<percentage>>s that correspond to the [=origin color's=]
1013
+
HSL saturation and lightness,
984
1014
after its conversion to sRGB
985
-
* <dfn value for="hsl()">alpha</dfn> is a <<number>>or <<percentage>>that corresponds to the [=origin color's=] alpha transparency
1015
+
* <dfn value for="hsl()">alpha</dfn> is a <<number>> that corresponds to the [=origin color's=] alpha transparency
986
1016
987
1017
<div class="example">
988
1018
This adds 180 degrees to the hue angle, giving a complementary color.
@@ -993,7 +1023,7 @@ the allowed [=channel keywords=] are:
993
1023
lightseagreen is hsl(177deg 70% 41%), so --complement is <span class="swatch" style="--color: hsl(357deg 70% 41%)"></span> hsl(357deg 70% 41%)
994
1024
</div>
995
1025
996
-
Relative color syntax is only applicable to the non-legacy HSL syntactic forms.
1026
+
Relative HSL color syntax is only applicable to the non-legacy HSL syntactic forms.
997
1027
998
1028
<h3 id="relative-HWB">Relative HWB Colors</h3>
999
1029
@@ -1016,9 +1046,9 @@ the allowed [=channel keywords=] are:
1016
1046
after its conversion to sRGB,
1017
1047
normalized to a [0deg, 360deg) range
1018
1048
* <dfn value for="hwb()">w</dfn> and <dfn value for="hwb()">b</dfn>
1019
-
are <<percentage>>s or <<number>>s that correspond to the [=origin color's=] HWB whiteness and blackness
1049
+
are <<percentage>>s that correspond to the [=origin color's=] HWB whiteness and blackness
1020
1050
after its conversion to sRGB
1021
-
* <dfn value for="hwb()">alpha</dfn> is a <<number>>or <<percentage>>that corresponds to the [=origin color's=] alpha transparency
1051
+
* <dfn value for="hwb()">alpha</dfn> is a <<number>> that corresponds to the [=origin color's=] alpha transparency
1022
1052
1023
1053
<h3 id="relative-Lab">Relative Lab Colors</h3>
1024
1054
@@ -1036,31 +1066,34 @@ The grammar of the ''lab()'' function is extended as follows:
1036
1066
Within a [=relative color=] syntax ''lab()'' function,
1037
1067
the allowed [=channel keywords=] are:
1038
1068
1039
-
* <dfn value for="lab()">l</dfn> is a <<percentage>> or <<number>>
1069
+
* <dfn value for="lab()">l</dfn> is a <<number>>
1040
1070
that corresponds to the [=origin color's=] CIE Lightness
1041
-
* <dfn value for="lab()">a</dfn> and <dfn value for="lab()">b</dfn> are <<percentage>>s or <<number>>s
1071
+
* <dfn value for="lab()">a</dfn> and <dfn value for="lab()">b</dfn> are <<number>>s
1042
1072
that correspond to the [=origin color's=] CIELab a and b axes
1043
-
* <dfn value for="lab()">alpha</dfn> is a <<number>>or <<percentage>>that corresponds to the [=origin color's=] alpha transparency
1073
+
* <dfn value for="lab()">alpha</dfn> is a <<number>> that corresponds to the [=origin color's=] alpha transparency
1044
1074
1045
1075
<div class="example">
1046
1076
Multiple ways to adjust the transparency of a base color:
1047
1077
1048
-
* ''lab(from var(--mycolor) l a b / 100%)'' sets the alpha of ''var(--mycolor)'' to 100% regardless of what it originally was.
1078
+
* ''lab(from var(--mycolor) l a b / 100%)'' sets the alpha of ''var(--mycolor)'' to 1.0, regardless of what it originally was.
1049
1079
* ''lab(from var(--mycolor) l a b / calc(alpha * 0.8))'' reduces the alpha of ''var(--mycolor)'' by 20% of its original value.
1050
-
* ''lab(from var(--mycolor) l a b / calc(alpha - 20%))'' reduces the alpha of ''var(--mycolor)'' by 20% of 100%.
1051
1080
1052
1081
Note that all the adjustments are lossless in the sense that no gamut clipping occurs, since lab() encompasses all visible color.
1053
-
This is not true for the alpha adjustments in the sRGB based functions (such as 'rgb()', 'hsl()', or 'hwb()'), which would also convert to sRGB in addition to adjusting the alpha transparency.
1082
+
This is not true for the alpha adjustments in the sRGB based functions
1083
+
(such as 'rgb()', 'hsl()', or 'hwb()'),
1084
+
which would also convert to sRGB
1085
+
as a necessary step for calculation of HSL or HWB,
1086
+
in addition to adjusting the alpha transparency.
1054
1087
</div>
1055
1088
1056
1089
<div class="example">
1057
1090
Fully desaturating a color to gray, keeping the exact same lightness:
// mygray is lab(62.753% 0 0) which is rgb(59.515% 59.515% 59.515%)
1096
+
// mygray is lab(62.753 0 0) which is rgb(59.515% 59.515% 59.515%)
1064
1097
</pre>
1065
1098
</div>
1066
1099
@@ -1080,11 +1113,11 @@ The grammar of the ''oklab()'' function is extended as follows:
1080
1113
Within a [=relative color=] syntax ''oklab()'' function,
1081
1114
the allowed [=channel keywords=] are:
1082
1115
1083
-
* <dfn value for="oklab()">l</dfn> is a <<percentage>> or<<number>>
1116
+
* <dfn value for="oklab()">l</dfn> is a <<number>>
1084
1117
that corresponds to the [=origin color's=] Oklab Lightness
1085
-
* <dfn value for="oklab()">a</dfn> and <dfn value for="oklab()">b</dfn> are <<percentage>>s or <<number>>s
1118
+
* <dfn value for="oklab()">a</dfn> and <dfn value for="oklab()">b</dfn> are <<number>>s
1086
1119
that correspond to the [=origin color's=] Oklab a and b axes
1087
-
* <dfn value for="oklab()">alpha</dfn> is a <<number>>or <<percentage>>that corresponds to the [=origin color's=] alpha transparency
1120
+
* <dfn value for="oklab()">alpha</dfn> is a <<number>> that corresponds to the [=origin color's=] alpha transparency
1088
1121
1089
1122
<h3 id="relative-LCH">Relative LCH Colors</h3>
1090
1123
@@ -1102,48 +1135,45 @@ The grammar of the ''lch()'' function is extended as follows:
1102
1135
Within a [=relative color=] syntax ''lch()'' function,
1103
1136
the allowed [=channel keywords=] are:
1104
1137
1105
-
* <dfn value for="lch()">l</dfn> is a <<percentage>> or <<number>>
1138
+
* <dfn value for="lch()">l</dfn> is a <<number>>
1106
1139
that corresponds to the [=origin color's=] CIE Lightness
1107
-
* <dfn value for="lch()">c</dfn> is a <<percentage>> or<<number>>
1140
+
* <dfn value for="lch()">c</dfn> is a <<number>>
1108
1141
that corresponds to the [=origin color's=] LCH chroma
1109
1142
* <dfn value for="lch()">h</dfn> is an <<angle>>
1110
1143
that corresponds to the [=origin color's=] LCH hue,
1111
1144
normalized to a [0deg, 360deg) range.
1112
-
* <dfn value for="lch()">alpha</dfn> is a <<number>>or <<percentage>>that corresponds to the [=origin color's=] alpha transparency
1145
+
* <dfn value for="lch()">alpha</dfn> is a <<number>> that corresponds to the [=origin color's=] alpha transparency
1113
1146
1114
-
Because LCH is both perceptually uniform and chroma-preserving,
1115
-
and because the axes correspond to easily understood attributes of a color,
1116
-
LCH is a good choice for color manipulation.
1117
1147
1118
1148
<div class="example">
1119
1149
''lch(from peru calc(l * 0.8) c h)'' produces a color that is 20% darker than <span class="swatch" style="--color: peru"></span> peru or lch(62.2532% 54.0114 63.6769), with its chroma and hue left unchanged.
1120
-
The result is <span class="swatch" style="--color: rgb(57.58% 32.47% 3.82%)"></span> lch(49.80256% 54.0114 63.6769)
1150
+
The result is <span class="swatch" style="--color: rgb(57.58% 32.47% 3.82%)"></span> lch(49.80256 54.0114 63.6769)
1121
1151
</div>
1122
1152
1123
1153
<div class="example">
1124
1154
This adds 180 degrees to the hue angle, giving the complementary color.
0 commit comments