Animate SVG Icons with Claude and Plain CSS

Ask Claude for a small, accessible CSS animation for any SVG icon, then tune timing yourself. No animation library needed.

What you'll build

A "check" icon that draws itself when it appears, and a bell icon that wiggles on hover. Both use plain CSS, so they work in any framework and cost zero JavaScript.

Step 1: Prepare the SVG

Give each part you want to animate a class. Keep the viewBox, and remove fixed width/height so CSS controls the size.

html
<svg class="icon-check" viewBox="0 0 24 24" fill="none" aria-hidden="true">
  <path class="icon-check__path" d="M4 12.5l5 5L20 6.5"
        stroke="currentColor" stroke-width="2.5"
        stroke-linecap="round" stroke-linejoin="round" />
</svg>

Step 2: Prompt Claude

Be specific about the motion, the duration and the limits. Ask for CSS only.

text
Here is an SVG (below). Write CSS only, no JavaScript, that:
1. Draws .icon-check__path from start to end in 600ms with ease-out, once, on load.
2. Uses stroke-dasharray / stroke-dashoffset.
3. Disables the animation inside @media (prefers-reduced-motion: reduce).
Return one CSS block and a one-line explanation of each property.

<svg>...paste your SVG...</svg>

Step 3: Check the result

A good answer looks roughly like this:

css
.icon-check__path {
  stroke-dasharray: 24;
  stroke-dashoffset: 24;
  animation: draw 600ms ease-out forwards;
}

@keyframes draw {
  to { stroke-dashoffset: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .icon-check__path { animation: none; stroke-dashoffset: 0; }
}

The 24 is the path length. If the line jumps or stops early, measure the real length in the browser console with document.querySelector('.icon-check__path').getTotalLength() and use that number.

Step 4: A hover wiggle

EffectProperty to animateTypical duration
Draw-instroke-dashoffset400–800ms
Wiggletransform: rotate()300–500ms
Pulsetransform: scale() + opacity1–2s, infinite

Ask Claude for the bell wiggle the same way. Name the trigger (:hover), the property and the duration.

Gotchas

  • Animate transform and opacity where you can. They are cheap for the browser; animating width or top is not.
  • Set transform-origin for rotations, or the icon spins around its corner.
  • Always keep the reduced-motion rule. Some people get dizzy from motion.

FAQ

Do I need an animation library for this?

No. For simple icon motion, CSS keyframes are enough and add no JavaScript.

Which Claude model should I use?

Any current Claude model can write this kind of CSS. Use the cheapest one that gives correct output for your icon.

Sources

  1. MDN: Using CSS animations
  2. MDN: prefers-reduced-motion
  3. Anthropic: Prompt engineering overview

Keep learning

Everything on Learn