How SMIL Animate Works in SVG

Synchronized Multimedia Integration Language (SMIL) allows developers to animate Scalable Vector Graphics (SVG) directly within XML markup without relying on external CSS keyframes or JavaScript. By embedding the <animate> element inside or linked to an SVG shape, you can transition numerical values, colors, coordinates, and transformation attributes over specified timeframes. This guide explains the core mechanisms, essential attributes, and execution lifecycle of the SMIL <animate> element.

The Basic Mechanism of <animate>

The <animate> element functions by targeting a specific attribute of an SVG element and interpolating its value from a starting state to an ending state over a defined duration.

To apply an animation, the <animate> tag is typically nested directly inside the target SVG element (such as a <circle>, <rect>, or <path>):

<svg width="200" height="200" viewBox="0 0 200 200">
  <circle cx="50" cy="100" r="30" fill="blue">
    <animate 
      attributeName="cx" 
      from="50" 
      to="150" 
      dur="2s" 
      repeatCount="indefinite" />
  </circle>
</svg>

Alternatively, the element can target an external node using the href (or legacy xlink:href) attribute referencing the target element’s id.

Key Attributes Controlling Transitions

The SMIL engine relies on specific attributes to calculate and render transitions:

Timing, Triggers, and Fill Modes

SMIL offers powerful synchronization controls for starting, ending, and persisting visual states:

Triggering with begin and end

The begin attribute sets when the transition starts. It can be a fixed clock time (begin="0s"), a delayed time (begin="2s"), or an event-based trigger. Event triggers allow interaction handling directly in markup, such as begin="click" or begin="button.click+0.5s".

Maintaining State with fill

By default, an animated attribute resets to its original value when the duration ends. Setting fill="freeze" instructs the renderer to retain the final animated state (to value) after completion. The default value is fill="remove".

Advanced Interpolation and Pacing

The SMIL engine determines transition pacing via the calcMode attribute:

Through these combined declarative parameters, the SVG rendering engine continuously calculates intermediate attribute values on the compositor level, delivering smooth vector transitions while keeping the animation self-contained within the SVG file format.