Skip to content
SiteEmail

This article picks up where SVG UI Tricks left off. We already covered how to change fills and strokes with class toggles and how to reveal paths with stroke-dashoffset . Here we will briefly cover how to turn those same techniques into CSS keyframe animations and find all SVG-specific animation constraints in Gameface collected in one place.

Inline SVGs are part of the DOM, so every animation technique from the UI Animations article (transitions, @keyframes, the Web Animations API) applies to SVG elements exactly the same way it applies to a <div> or a <button>. There is no special SVG animation mode to learn.

The SVG UI Tricks article used CSS transitions on the weapon rarity icon to interpolate between two states on a class change. Transitions work well for that one-time reactive change, but effects that should loop continuously (a blinking spark, a breathing glow, a pulsing opacity) call for @keyframes instead.

Since SVG presentation attributes (fill, stroke, opacity, transform) are valid CSS properties on inline elements, you write keyframe rules for them the same way you would for any HTML element. The following examples all build on the same weapon icon from the SVG UI Tricks article and demonstrate different properties being animated:

Legendary: spark blink and blade glow

rarity-animations.css
@keyframes spark-blink {
0% {
opacity: 1;
transform: scale(1);
}
50% {
opacity: 0.3;
transform: scale(0.7);
}
100% {
opacity: 1;
transform: scale(1);
}
}
@keyframes blade-glow {
0% {
filter: drop-shadow(0 0 0.3vh rgba(78, 242, 217, 0.2));
}
50% {
filter: drop-shadow(0 0 1.2vh rgba(78, 242, 217, 0.6));
}
100% {
filter: drop-shadow(0 0 0.3vh rgba(78, 242, 217, 0.2));
}
}
.weapon-button--legendary .weapon-icon__spark {
animation: spark-blink 1.6s ease-in-out infinite;
}
.weapon-button--legendary .weapon-icon {
animation: blade-glow 2s ease-in-out infinite;
}

Rare: stroke color shimmer

rarity-animations.css
@keyframes stroke-shimmer {
0% {
stroke: #ffd89d;
}
50% {
stroke: #f2a34e;
}
100% {
stroke: #ffd89d;
}
}
.weapon-button--rare .weapon-icon__blade {
animation: stroke-shimmer 2.4s ease-in-out infinite;
}

Locked: slow dim pulse

rarity-animations.css
@keyframes locked-pulse {
0% {
opacity: 1;
}
50% {
opacity: 0.5;
}
100% {
opacity: 1;
}
}
.weapon-button--disabled .weapon-icon {
animation: locked-pulse 3s ease-in-out infinite;
}

Each animation starts when its modifier class is applied and stops when the class is removed, the same toggle pattern as the static rarity variants. The SVG structure and the CSS-variable system from the examples in the SVG UI Tricks article stay completely untouched - the keyframes just layer on top of it.

The same applies to the stroke-dash techniques from SVG UI Tricks. The stroke-dashoffset property is animatable through both transitions and keyframes, so you can use @keyframes for creating complex multi-stage stroke animations.

Animating inline SVGs works the same as animating any other DOM element, but there are several SVG-specific constraints in Gameface worth being aware of.

Not all SVG properties carry the same animation cost. Inline SVGs are never cached in GPU textures, they follow DOM redraw rules and are re-tessellated (vector paths converted to renderable geometry) when their geometry changes. Appearance-only properties avoid this cost.

Lower cost (appearance only)Higher cost (geometry changes)
fill, stroke, opacitywidth, height
stroke-dashoffsetd (path data)
filter (on parent element)transform (scale, when it changes bounds)