This example shows how to use the palette-mix()
function to create a new palette by blending two others.
HTML
The HTML contains three paragraphs to apply our font information to:
<p class="yellowPalette">Yellow palette</p>
<p class="bluePalette">Blue palette</p>
<p class="mixedPalette">Mixed palette</p>
CSS
In the CSS, we import a color font from Google Fonts, and define two custom font-palette
values using the @font-palette-values
at-rule. We then apply three different font-palette
values to the paragraphs — --yellow
, --blue
, and a new green palette, created using palette-mix()
to blend the blue and yellow palettes together.
@import url("https://fonts.googleapis.com/css2?family=Nabla&display=swap");
@font-palette-values --blueNabla {
font-family: Nabla;
base-palette: 2; /* this is Nabla's blue palette */
}
@font-palette-values --yellowNabla {
font-family: Nabla;
base-palette: 7; /* this is Nabla's yellow palette */
}
p {
font-family: "Nabla";
font-size: 4rem;
text-align: center;
margin: 0;
}
.yellowPalette {
font-palette: --yellowNabla;
}
.bluePalette {
font-palette: --blueNabla;
}
.mixedPalette {
font-palette: palette-mix(in lch, --blueNabla 55%, --yellowNabla 45%);
}
Result
The output looks like this: