TutorialSeptember 25, 2025·7 min read
Creating Animated Characters with SVG and CSS
Why load sprite sheets when you can draw your character once with SVG and animate it with CSS? Here's how Dhiva Pet does it.
The SVG Skeleton
Each character is made of named SVG elements:
<svg viewBox="0 0 100 100"> <ellipse class="body" cx="50" cy="62" rx="22" ry="20" /> <circle class="head" cx="50" cy="36" r="20" /> <ellipse class="arm-l" cx="30" cy="60" rx="7" ry="10" /> <ellipse class="arm-r" cx="70" cy="60" rx="7" ry="10" /> <ellipse class="leg-l" cx="42" cy="82" rx="7" ry="6" /> <ellipse class="leg-r" cx="58" cy="82" rx="7" ry="6" /> </svg>
State-Driven Animation
The renderer adds a state class to the pet container:
petEl.classList.add('pet--walk');And CSS keys off that state:
.pet--walk .leg-l {
animation: legSwing 0.45s ease-in-out infinite;
transform-origin: 42px 78px;
}
@keyframes legSwing {
0%, 100% { transform: rotate(-14deg); }
50% { transform: rotate(14deg); }
}Performance Wins
- SVG paths are a few hundred bytes each
- CSS animations are GPU-accelerated
- No sprite-sheet memory overhead
- Infinitely scalable to any size
Each Dhiva Pet character animates smoothly even on 4K displays with barely any CPU usage.