Skip to content

Commit ff4d0c3

Browse files
committed
[css-coor-4] some HSL vs LCH comparisons
1 parent 8056031 commit ff4d0c3

File tree

1 file changed

+84
-15
lines changed

1 file changed

+84
-15
lines changed

css-color-4/Overview.bs

+84-15
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ The RGB hexadecimal notations: ''#RRGGBB''</h3>
576576
The alpha channel of the color is fully opaque.
577577

578578
<div class='example'>
579-
In other words, ''#00ff00'' represents the same color as ''rgb(0 255 0)'' (a lime green).
579+
In other words, <span class="swatch" style="--color: #00ff00"></span> ''#00ff00'' represents the same color as <span class="swatch" style="--color: #00ff00"></span> ''rgb(0 255 0)'' (a lime green).
580580
</div>
581581

582582
<dt>8 digits
@@ -588,7 +588,7 @@ The RGB hexadecimal notations: ''#RRGGBB''</h3>
588588
and ''ff'' represent a fully opaque color.
589589

590590
<div class='example'>
591-
In other words, ''#0000ffcc'' represents the same color as ''rgb(0 0 100% / 80%)'' (a slightly-transparent blue).
591+
In other words, <span class="swatch" style="--color: #0000ffcc"></span> ''#0000ffcc'' represents the same color as <span class="swatch" style="--color: #0000ffcc"></span> ''rgb(0 0 100% / 80%)'' (a slightly-transparent blue).
592592
</div>
593593

594594
<dt>3 digits
@@ -604,7 +604,7 @@ The RGB hexadecimal notations: ''#RRGGBB''</h3>
604604

605605
<div class='example'>
606606
This syntax is often explained by saying that it's identical to a 6-digit notation obtained by "duplicating" all of the digits.
607-
For example, the notation ''#123'' specifies the same color as the notation ''#112233''.
607+
For example, the notation <span class="swatch" style="--color: #123"></span> ''#123'' specifies the same color as the notation <span class="swatch" style="--color: #123"></span> ''#112233''.
608608
This method of specifying a color has lower "resolution" than the 6-digit notation;
609609
there are only 4096 possible colors expressible in the 3-digit hex syntax,
610610
as opposed to approximately 17 million in 6-digit hex syntax.
@@ -975,18 +975,18 @@ System Colors</h3>
975975

976976
In general, the <<system-color>> keywords
977977
reflect <em>default</em> color choices made by the user, the browser, or the OS.
978-
They are typically used in the brwser default stylesheet, for this reason.
978+
They are typically used in the browser default stylesheet, for this reason.
979979

980980
To maintain legibility,
981981
the <<system-color>> keywords also respond to light mode or dark mode changes.
982982

983983

984984
<div class="example" id="LM-DM-links">
985-
For example, traditional blue link text is legible on a white background
985+
For example, traditional <span class="swatch" style="--color: blue"></span> blue link text is legible on a <span class="swatch" style="--color: #fff"></span> white background
986986
(WCAG contrast 8.59:1, AAA pass)
987-
but would not be legible on a black background
987+
but would not be legible on a <span class="swatch" style="--color: #000"></span> black background
988988
(WCAG contrast 2.44:1, AA fail).
989-
Instead, a lighter blue such as #81D9FE would be used in dark mode
989+
Instead, a lighter blue such as <span class="swatch" style="--color: #81D9FE"></span> #81D9FE would be used in dark mode
990990
(WCAG contrast 13.28:1, AAA pass).
991991
<div style="margin:1em; margin-left: 2em; text-decoration: underline; background: inherit">
992992
<p style="padding: 4px; background-color: white; color: blue"> Legible link text</p>
@@ -1227,20 +1227,18 @@ HSL Colors: ''hsl()'' and ''hsla()'' functions</h2>
12271227
It's interpreted identically to the fourth argument of the ''rgb()'' function.
12281228
If omitted, it defaults to ''100%''.
12291229

1230+
HSL colors resolve to sRGB.
1231+
12301232
<div class='example'>
12311233
For example, an ordinary red,
1232-
the same color you would see from the keyword ''red''
1233-
or the hex notation ''#f00'',
1234-
is represented in HSL as ''hsl(0deg 100% 50%)''.
1234+
the same color you would see from the keyword <span class="swatch" style="--color: red"></span>&nbsp;''red''
1235+
or the hex notation <span class="swatch" style="--color: red"></span>&nbsp;''#f00'',
1236+
is represented in HSL as <span class="swatch" style="--color: red"></span>&nbsp;''hsl(0deg 100% 50%)''.
12351237
</div>
12361238

1237-
The advantage of HSL over RGB is that it is far more intuitive:
1239+
An advantage of HSL over RGB is that it is more intuitive:
12381240
one can guess at the colors they want,
12391241
and then tweak.
1240-
It is also easier to create sets of matching colors
1241-
(by keeping the hue the same and varying the saturation and lightness).
1242-
1243-
HSL colors resolve to sRGB.
12441242

12451243
<div class='example'>
12461244
For example, the following colors can all be generated off of the basic "green" hue,
@@ -1254,6 +1252,77 @@ HSL Colors: ''hsl()'' and ''hsla()'' functions</h2>
12541252
</pre>
12551253
</div>
12561254

1255+
An advantage of HSL over LCH is that,
1256+
regardless of manipulation,
1257+
the result always lies inside the sRGB gamut.
1258+
A disadvantage of HSL over LCH
1259+
is that hue manipulation changes the visual lightness,
1260+
and that hues are not evenly spaced apart.
1261+
1262+
It is thus easier in HSL to create sets of matching colors
1263+
(by keeping the hue the same and varying the saturation and lightness),
1264+
compared to maipulating the sRGB component values;
1265+
however, because the lightness is simply the mean of the gamma-corrected
1266+
red, green and blue components
1267+
it does not correspond to the visual perception of lightness
1268+
across hues.
1269+
1270+
<div class="example">
1271+
For example, <span class="swatch" style="--color: blue"></span>&nbsp;''blue'''
1272+
is represented in HSL as
1273+
<span class="swatch" style="--color: blue"></span>&nbsp;''hsl(240deg 100% 50%)
1274+
while <span class="swatch" style="--color: yellow"></span>&nbsp;''yellow'''
1275+
is <span class="swatch" style="--color: yellow"></span>&nbsp;''hsl(60deg 100% 50%)''.
1276+
Both have an HSL Lightness of 50%,
1277+
but clearly the yellow looks much lighter than the blue.
1278+
1279+
In LCH, sRGB blue is
1280+
<span class="swatch" style="--color: blue"></span>&nbsp;''lch(29.6% 131.2 301.3)''
1281+
while
1282+
sRGB yellow is
1283+
<span class="swatch" style="--color: yellow"></span>&nbsp;''lch(97.6% 94.7 99.6)''.
1284+
The LCH Lightnesses of 29.6% and 97.6% clearly reflect
1285+
the visual lightnesses of the two colors.
1286+
</div>
1287+
1288+
The hue angle in HSL is not perceptually uniform;
1289+
colors appear bunched up in some areas
1290+
and widely spaced in others.
1291+
1292+
<div class="example">
1293+
For example, the pair of hues
1294+
<!--
1295+
hsl(220 100% 50%) 42.114139000774955, 97.39536874737148, 290.5815091930946
1296+
hsl(250 100% 50%) 30.84988530751331, 129.71314978865763, 302.1290808073227
1297+
-->
1298+
<!--
1299+
hsl(50 100% 50%) 86.84897521929184, 86.24043356068755, 87.26505542654621
1300+
hsl(80 100% 50%) 91.96771031614921, 98.8076382873608, 119.14730687158351
1301+
-->
1302+
<span class="swatch" style="--color: hsl(220 100% 50%)"></span>&nbsp;''hsl(220deg 100% 50%)''
1303+
and
1304+
<span class="swatch" style="--color: hsl(250 100% 50%)"></span>&nbsp;''hsl(250deg 100% 50%)''
1305+
have an HSL hue difference of 30deg and look fairly similar,
1306+
while another pair of colors
1307+
<span class="swatch" style="--color: hsl(50 100% 50%)"></span>&nbsp;''hsl(50deg 100% 50%)''
1308+
and
1309+
<span class="swatch" style="--color: hsl(80 100% 50%)"></span>&nbsp;''hsl(80deg 100% 50%)'',
1310+
which also have a hue difference of 30deg, look very different.
1311+
1312+
In LCH, the same pair of colors
1313+
<span class="swatch" style="--color: hsl(220 100% 50%)"></span>&nbsp;''lch(42.1% 97.4 290.6)''
1314+
and
1315+
<span class="swatch" style="--color: hsl(250 100% 50%)"></span>&nbsp;''lch(30.8% 129.7 302.1)''
1316+
have a hue difference of 11.5deg
1317+
while the second pair
1318+
<span class="swatch" style="--color: hsl(50 100% 50%)"></span>&nbsp;''lch(86.8% 86.2 87.3)''
1319+
and
1320+
<span class="swatch" style="--color: hsl(80 100% 50%)"></span>&nbsp;''lch(92.0% 98.8 119.1)''
1321+
have a hue difference of 31.8deg
1322+
reflecting the visual separation of hues.
1323+
1324+
</div>
1325+
12571326
For legacy reasons,
12581327
''hsl()'' also supports an alternate syntax
12591328
that separates all of its arguments with commas:

0 commit comments

Comments
 (0)