This example illustrates how to animate font-palette
value changes to create a smooth font animation.
HTML
The HTML contains a single paragraph of text to animate:
<p>color-palette<br />animation</p>
CSS
In the CSS, we import a color font called Nabla from Google Fonts, and define two custom font-palette
values using the @font-palette-values
at-rule. We then create @keyframes
that animate between these two palettes, and apply this animation to our paragraph.
@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 --greyNabla {
font-family: Nabla;
base-palette: 3; /* this is Nabla's grey palette */
}
@keyframes animate-palette {
from {
font-palette: --greyNabla;
}
to {
font-palette: --blueNabla;
}
}
p {
font-family: "Nabla";
font-size: 5rem;
margin: 0;
text-align: center;
animation: animate-palette 4s infinite alternate linear;
}
Result
The output looks like this:
Note: Browsers that still implement discrete
font-palette
animation will flip between the two palettes rather than smoothly animating.