@@ -124,23 +124,33 @@ Mixing colors: the ''color-mix()'' function {#color-mix}
124124 <dfn>color-mix()</dfn> = color-mix( in <<colorspace>> , [ <<color>> && <<percentage>> ? ]#{2})
125125</pre>
126126
127- If a percentage is omitted, it defaults to 50% (an equal mix of the two colors).
127+ The percentages are normalized as follows:
128128
129- The result is produced via the following algorithm:
129+ 1. Let <var> p1</var> be the first percentage and <var> p2</var> the second one.
130+ 2. If both percentages are omitted, they each default to 50% (an equal mix of the two colors).
131+ 3. Otherwise, if <var> p2</var> is omitted, it becomes 100% - <var> p1</var>
132+ 4. Otherwise, if <var> p1</var> is omitted, it becomes 100% - <var> p2</var>
133+ 5. Otherwise, if both are provided but do not add up to 100%,
134+ they are scaled accordingly so that they add up to 100%.
135+ This means that
136+ <var> p1</var> becomes <var> p1</var> / <var> p1</var> + <var> p2</var>
137+ and
138+ <var> p2</var> becomes <var> p2</var> / <var> p1</var> + <var> p2</var> .
130139
131- 1. If a percentage is omitted, it defaults to 50% (an equal mix of the two colors).
132- If the color space is omitted, it defaults to 'lch' .
133- 2. Both colors are converted to the specified [=colorspace=] .
140+ Issue: Should we handle p1 + p2 < 100% differently? E.g. a mix with `transparent`?
141+
142+ After normalizing both percentages, the result is produced via the following algorithm:
143+
144+ 1. Both colors are converted to the specified [=colorspace=] .
134145If the specified colorspace has a smaller gamut
135146than the one in which the color to be adjusted is specified,
136147gamut mapping will occur.
137- 3 . Colors are then <a href="../css-color-4/#interpolation">interpolated in the specified colorspace</a> .
148+ 2 . Colors are then <a href="../css-color-4/#interpolation">interpolated in the specified colorspace</a> .
138149The result of mixing is the color at the specified percentage along the progression
139150of the second color to the first color.
140151
141- Note: As a corrollary, 0% just returns the second color converted to the specified colorspace,
142- 100% returns the first color converted to the specified colorspace,
143- and 50% produces an equal mix of both.
152+ Note: As a corrollary, a percentage of 0% just returns the other color converted to the specified colorspace,
153+ and a percentage of 100% returns the same color converted to the specified colorspace.
144154
145155<div class="example">
146156 This example produces a mixture of 40% <span class="swatch" style="--color: peru"></span> peru
0 commit comments