Skip to content
Office Open

PPTX

Animations

Add entrance, exit, emphasis, and motion path animations to shapes

Add animation effects to shapes to control how they appear and behave during a presentation.

#Basic Usage

Animations live at the slide level, not on shapes — CT_Shape has no timing child in the XSD. Each slide exposes an animations array whose entries carry a shapeId (the target shape's cNvPr id) plus the animation fields inline:

ts
import { generatePresentation } from "@office-open/pptx";
JSON
{
  "slides": [
    {
      "children": [
        {
          "shape": {
            "id": 2,
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "15.9cm",
            "height": "6.6cm",
            "textBody": { "text": "Animated shape" }
          }
        }
      ],
      "animations": [{ "shapeId": 2, "type": "fade", "duration": 800 }]
    }
  ]
}

Each animations entry pairs a shapeId with the animation preset fields. The shapeId matches the id set on the target shape's NonVisualDrawingProperties (the cNvPr id), which you assign via shape.id; the remaining fields are the preset documented in the type-specific sections below.

#Targeting Shapes

Fresh documents can reference the target by shapeName instead — the library resolves it to the shape's cNvPr id at compile time against the shapes of the same slide:

json
{
  "children": [
    {
      "shape": {
        "name": "Hero",
        "x": "1.3cm",
        "y": "1.3cm",
        "width": "15.9cm",
        "height": "6.6cm",
        "textBody": {
          "text": "Named"
        }
      }
    }
  ],
  "animations": [
    {
      "shapeName": "Hero",
      "type": "fade",
      "duration": 800
    }
  ]
}

shapeName is the authoring channel: names stay stable while ids renumber, and an unknown or duplicated name throws at compile time instead of emitting a dangling spTgt @spid. shapeId is the round-trip channel (parsed sources keep their source ids) and wins when both are set.

#Animation Types

#Entrance Animations (class: "entrance", default)

TypeDescriptionSupported Directions
appearInstantly appear—
fadeFade in—
flyFly in from edgeleft, right, up, down
wipeWipe in from edgeleft, right, up, down
dissolveDissolve in—
splitSplit inhorizontal, vertical
blindsBlinds effecthorizontal, vertical
checkerCheckerboardhorizontal, vertical
randomBarsRandom barshorizontal, vertical
wheelWheel spokes—
zoomZoom in—
coverCover from edgeleft, right, up, down
pushPush from edgeleft, right, up, down
stripsStrips from cornerleft, right, up, down

#Exit Animations (class: "exit")

Same types as entrance, but with class: "exit":

json
[
  { "shapeName": "Title", "type": "fade", "class": "exit", "duration": 800 },
  { "shapeName": "Title", "type": "fly", "class": "exit", "direction": "right" }
]

#Emphasis Animations (class: "emphasis")

emphasisTypeDescription
growShrinkScale up then back
spinFull rotation
colorChangeChange color (requires color)
transparencyFade to semi-transparent
boldFlashBold text flash
waveWave effect
pulsePulse effect
growWithTurnGrow with rotation
json
[
  { "shapeName": "Title", "class": "emphasis", "emphasisType": "growShrink", "duration": 800 },
  { "shapeName": "Title", "class": "emphasis", "emphasisType": "spin", "duration": 1000 },
  { "shapeName": "Title", "class": "emphasis", "emphasisType": "colorChange", "color": "FF0000" }
]

#Motion Path Animations

pathTypeDescription
lineStraight line
arcArc curve
circleCircular path
curveS-curve
figureEightFigure-eight
bounceBounce path
loopLoop path
customPathCustom SVG path (requires path)
json
[
  { "shapeName": "Title", "pathType": "circle", "duration": 1500 },
  {
    "shapeName": "Title",
    "pathType": "customPath",
    "path": "M 0 0 L 100 0 L 100 100 L 0 100 Z",
    "duration": 1200
  }
]

#Media Playback (class: "mediaCall")

Trigger audio/video playback on a media shape (a { video } / { audio } child) with mediaType. The shapeId must point at the media frame:

json
[
  {
    "shapeName": "Video 1",
    "class": "mediaCall",
    "mediaType": "playVideo",
    "fullScreen": true,
    "showWhenStopped": true
  },
  {
    "shapeName": "Video 1",
    "class": "mediaCall",
    "mediaType": "playAudio",
    "volume": 80,
    "mute": false
  }
]
PropertyTypeDescription
mediaType"playAudio" | "playVideo" | "play"Media animation type
isNarrationbooleanMedia is a narration track
fullScreenbooleanPlay video full-screen
volumenumberVolume level
mutebooleanMute audio
showWhenStoppedbooleanKeep the media frame visible when stopped

#Animation Options

PropertyTypeDefaultDescription
typeAnimationType"appear"Animation preset type
class"entrance" | "exit" | "emphasis" | "mediaCall""entrance"Animation category
durationnumber500Duration in milliseconds
delaynumber0Delay before start in milliseconds
triggerAnimationTrigger"onClick"How animation is triggered
directionAnimationDirection—Direction of the animation
emphasisTypeEmphasisType—Emphasis animation type (class="emphasis")
pathTypePathAnimationType—Motion path type
pathstring—Custom SVG path string
speednumber—Speed multiplier
repeatCountnumber—Number of repetitions
autoReversebooleanfalseAuto-reverse after completion
colorstring—Target color for colorChange
pathEditMode"relative" | "fixed" | "none"—Motion path edit mode
rotationAnglenumber—Motion path rotation in 1/60000ths of a degree (p:animRot @rAng; passed through raw)
motionFrom{ x: string; y: string }—Motion path start point
motionRotationCenter{ x: string; y: string }—Motion rotation center
zoomContentsbooleanfalseZoom contents during a scale animation

#Trigger Modes

json
[
  { "shapeName": "Title", "type": "fade", "trigger": "onClick" },
  { "shapeName": "Title", "type": "fade", "trigger": "withPrevious" },
  { "shapeName": "Title", "type": "fade", "trigger": "afterPrevious" }
]