Code

SVG

Animation (SMIL)

Advanced Declarative SVG animation via SMIL: <animate>, <animateTransform>, and <animateMotion> with <mpath>. MDN animate

animate: fill + ranimateTransform: rotateanimateTransform: scaleanimate: stroke-dashoffset draw effectanimateMotion + mpath: dot follows path
<!-- animate: attribute cycling -->
<circle cx="80" cy="70" r="35">
  <animate
    attributeName="fill"
    values="#4f46e5;#e11d48;#4f46e5"
    dur="4s"
    repeatCount="indefinite"/>
  <animate
    attributeName="r"
    values="35;45;35"
    dur="2s"
    repeatCount="indefinite"/>
</circle>

<!-- animateTransform: rotate -->
<polygon ...>
  <animateTransform
    attributeName="transform"
    type="rotate"
    from="0" to="360"
    dur="6s"
    repeatCount="indefinite"/>
</polygon>

<!-- stroke-dashoffset draw effect -->
<path stroke-dasharray="600"
      stroke-dashoffset="600">
  <animate
    attributeName="stroke-dashoffset"
    from="600" to="0"
    dur="3s"
    repeatCount="indefinite"/>
</path>

<!-- animateMotion + mpath -->
<defs>
  <path id="track"
    d="M 40 240 C 80 170 ..."/>
</defs>

<circle r="8" fill="#e11d48">
  <animateMotion
    dur="4s"
    repeatCount="indefinite"
    rotate="auto">
    <mpath href="#track"/>
  </animateMotion>
</circle>
Key Concepts
  • <animate> — animates any presentation attribute: fill, r, opacity, stroke-dashoffset, etc.
  • values — semicolon-separated keyframe values; or use from/to for two-point animations
  • dur — duration (e.g. 2s, 500ms); repeatCount="indefinite" loops forever
  • <animateTransform> — animates translate, rotate, scale, or skewX/Y
  • additive="sum" — adds the animation on top of the element's existing transform
  • <animateMotion> — moves an element along a path; rotate="auto" aligns to the tangent
  • <mpath href="#id"> — references a <path> element as the motion track