# Motion

> Entrance and data-update transitions, the fluid and subtle presets, turning motion off, and what reduced motion does.

Charts move by default. The entrance plays once a chart scrolls into view, and `update` moves the marks from the old layout to the new one instead of redrawing them.

```json
{
  "mark": {
    "type": "line",
    "strokeWidth": 2
  },
  "data": [
    {
      "date": "2019-01-01",
      "rate": 1.6
    },
    {
      "date": "2019-04-01",
      "rate": 2
    },
    {
      "date": "2019-07-01",
      "rate": 1.8
    },
    {
      "date": "2019-10-01",
      "rate": 1.8
    },
    {
      "date": "2020-01-01",
      "rate": 2.5
    },
    {
      "date": "2020-04-01",
      "rate": 0.3
    },
    {
      "date": "2020-07-01",
      "rate": 1
    },
    {
      "date": "2020-10-01",
      "rate": 1.2
    },
    {
      "date": "2021-01-01",
      "rate": 1.4
    },
    {
      "date": "2021-04-01",
      "rate": 4.2
    },
    {
      "date": "2021-07-01",
      "rate": 5.4
    },
    {
      "date": "2021-10-01",
      "rate": 6.2
    }
  ],
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": {
        "tickCount": 6
      }
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "Inflation (%)",
        "format": ".0f",
        "grid": true
      }
    }
  },
  "chrome": {
    "title": "US inflation reached 6.2% by the end of 2021",
    "subtitle": "US consumer prices, change from a year earlier, quarterly, 2019 to 2021 (%)"
  }
}
```

Press "2019 to 2024" to call `update` with a spec that has three more years of rows. The points already on the chart slide to their new positions as both axes rescale, the new quarters draw in, and the title changes with the spec. The library matches marks across the two layouts by their data values, so each quarter keeps its place in the line while it moves. The Code panel shows the spec as the page loaded it, not the state on screen.

## Presets

```json
{
  "mark": "bar",
  "data": [
    {
      "country": "India",
      "population": 1463000000
    },
    {
      "country": "China",
      "population": 1410000000
    },
    {
      "country": "United States",
      "population": 347000000
    },
    {
      "country": "Indonesia",
      "population": 285000000
    },
    {
      "country": "Pakistan",
      "population": 255000000
    },
    {
      "country": "Nigeria",
      "population": 240000000
    },
    {
      "country": "Brazil",
      "population": 217000000
    },
    {
      "country": "Bangladesh",
      "population": 175000000
    },
    {
      "country": "Russia",
      "population": 144000000
    },
    {
      "country": "Ethiopia",
      "population": 135000000
    }
  ],
  "encoding": {
    "y": {
      "field": "country",
      "type": "nominal",
      "sort": "-x"
    },
    "x": {
      "field": "population",
      "type": "quantitative",
      "axis": {
        "title": "Population",
        "format": ".2s"
      }
    }
  },
  "labels": {
    "density": "all",
    "format": ".3s"
  },
  "chrome": {
    "title": "India and China each have more than 1.4 billion people",
    "subtitle": "Population of the 10 most populous countries, 2025, UN projection"
  }
}
```

`animation` takes a preset name. `"fluid"` moves the entrance and later updates on a spring, and `"subtle"` shortens both to 250 milliseconds. Both start every bar at once, where the default lands them up to 80 milliseconds apart over an 800-millisecond entrance. `false` turns off all motion: the chart draws finished and updates swap at once.

```json title="fluid.json"
{
  "mark": "bar",
  "data": [{ "country": "India", "population": 1463000000 }],
  "encoding": {
    "y": { "field": "country", "type": "nominal" },
    "x": { "field": "population", "type": "quantitative" }
  },
  "animation": "fluid"
}
```

The object form sets each phase on its own, for example `animation: { enter: { duration: 600, ease: "snappy" }, update: false }`. A preset combines with it as `preset: "fluid"`, and any phase you set explicitly wins.

## Replay and when the entrance plays

```json
{
  "mark": {
    "type": "line",
    "strokeWidth": 2
  },
  "data": [
    {
      "year": "2016",
      "source": "Coal",
      "share": 31.2
    },
    {
      "year": "2016",
      "source": "Gas",
      "share": 34.8
    },
    {
      "year": "2016",
      "source": "Nuclear",
      "share": 20.3
    },
    {
      "year": "2016",
      "source": "Hydro",
      "share": 6.6
    },
    {
      "year": "2016",
      "source": "Wind",
      "share": 5.7
    },
    {
      "year": "2016",
      "source": "Solar",
      "share": 1.4
    },
    {
      "year": "2017",
      "source": "Coal",
      "share": 30.7
    },
    {
      "year": "2017",
      "source": "Gas",
      "share": 33
    },
    {
      "year": "2017",
      "source": "Nuclear",
      "share": 20.5
    },
    {
      "year": "2017",
      "source": "Hydro",
      "share": 7.5
    },
    {
      "year": "2017",
      "source": "Wind",
      "share": 6.5
    },
    {
      "year": "2017",
      "source": "Solar",
      "share": 2
    },
    {
      "year": "2018",
      "source": "Coal",
      "share": 28.2
    },
    {
      "year": "2018",
      "source": "Gas",
      "share": 36
    },
    {
      "year": "2018",
      "source": "Nuclear",
      "share": 19.8
    },
    {
      "year": "2018",
      "source": "Hydro",
      "share": 7
    },
    {
      "year": "2018",
      "source": "Wind",
      "share": 6.7
    },
    {
      "year": "2018",
      "source": "Solar",
      "share": 2.3
    },
    {
      "year": "2019",
      "source": "Coal",
      "share": 23.9
    },
    {
      "year": "2019",
      "source": "Gas",
      "share": 39.2
    },
    {
      "year": "2019",
      "source": "Nuclear",
      "share": 20
    },
    {
      "year": "2019",
      "source": "Hydro",
      "share": 7
    },
    {
      "year": "2019",
      "source": "Wind",
      "share": 7.3
    },
    {
      "year": "2019",
      "source": "Solar",
      "share": 2.6
    },
    {
      "year": "2020",
      "source": "Coal",
      "share": 19.6
    },
    {
      "year": "2020",
      "source": "Gas",
      "share": 41.3
    },
    {
      "year": "2020",
      "source": "Nuclear",
      "share": 20.1
    },
    {
      "year": "2020",
      "source": "Hydro",
      "share": 7.1
    },
    {
      "year": "2020",
      "source": "Wind",
      "share": 8.6
    },
    {
      "year": "2020",
      "source": "Solar",
      "share": 3.3
    },
    {
      "year": "2021",
      "source": "Coal",
      "share": 22.2
    },
    {
      "year": "2021",
      "source": "Gas",
      "share": 39
    },
    {
      "year": "2021",
      "source": "Nuclear",
      "share": 19.3
    },
    {
      "year": "2021",
      "source": "Hydro",
      "share": 6.1
    },
    {
      "year": "2021",
      "source": "Wind",
      "share": 9.3
    },
    {
      "year": "2021",
      "source": "Solar",
      "share": 4.1
    },
    {
      "year": "2022",
      "source": "Coal",
      "share": 19.9
    },
    {
      "year": "2022",
      "source": "Gas",
      "share": 40.4
    },
    {
      "year": "2022",
      "source": "Nuclear",
      "share": 18.5
    },
    {
      "year": "2022",
      "source": "Hydro",
      "share": 6
    },
    {
      "year": "2022",
      "source": "Wind",
      "share": 10.4
    },
    {
      "year": "2022",
      "source": "Solar",
      "share": 4.9
    },
    {
      "year": "2023",
      "source": "Coal",
      "share": 16.2
    },
    {
      "year": "2023",
      "source": "Gas",
      "share": 43.5
    },
    {
      "year": "2023",
      "source": "Nuclear",
      "share": 18.6
    },
    {
      "year": "2023",
      "source": "Hydro",
      "share": 5.8
    },
    {
      "year": "2023",
      "source": "Wind",
      "share": 10.1
    },
    {
      "year": "2023",
      "source": "Solar",
      "share": 5.8
    }
  ],
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "format": "%Y"
      }
    },
    "y": {
      "field": "share",
      "type": "quantitative",
      "axis": {
        "title": "Share of generation (%)",
        "grid": true
      }
    },
    "color": {
      "field": "source",
      "type": "nominal"
    }
  },
  "endpointLabels": true,
  "chrome": {
    "title": "Coal's share fell from 31% to 16% between 2016 and 2023",
    "subtitle": "Share of US generation from coal, gas, nuclear, hydro, wind and solar, 2016 to 2023 (%)"
  }
}
```

Replay mounts the chart again, so each line draws in from the left as it did when the chart first appeared. Without Replay the entrance plays once, when at least a quarter of the chart is in view, so a chart far down a page still animates when the reader reaches it. `animation: { enter: { trigger: "mount" } }` plays it at mount instead, which suits screenshot tests.

## Reduced motion

When a reader's system asks for reduced motion (`prefers-reduced-motion: reduce`), the chart draws finished and every update swaps instantly. That setting overrides the spec, so no `animation` value turns motion back on for that reader. Static SVGs and exports never animate.

## When an update swaps instead of moving

An update skips the transition and swaps to the new layout when:

- the mark type changes, or an encoding channel points at a different field;
- the container has just been resized;
- either layout has more marks than `animation.update.maxMarks` (500 for SVG marks);
- the entrance is still playing.

## Playback charts

A chart with `encoding.time` moves by playing through its periods, and it skips the entrance and update animations on this page. The bubbles of a [bubble playback](/docs/correlation/bubble-playback/) move at a steady pace from one period to the next, and the reader can pause, scrub and replay them, where an entrance plays once and is gone. The `playback` block times the run, as the [playback page](/docs/change-over-time/playback/) describes.

`animation: false` on a time spec turns off autoplay: the chart opens on the final period, and the reader can still press Play. `update` on a time spec never tweens. It keeps the playhead on the same period when the mark type, the time field and the key field are unchanged, and starts the run over otherwise.

## Fields that matter

| Field | What it does |
| --- | --- |
| `animation` | `true` or left out for the defaults, `false` for no motion, `"fluid"` or `"subtle"` for a preset, or an object per phase. |
| `animation.enter` | The entrance: `duration`, `ease`, `stagger` and `trigger` (`"visible"` or `"mount"`). |
| `animation.update` | Transitions on `update`: `duration`, `ease` and `maxMarks`. |
| `animation.exit` | How removed marks fade out during an update. |
| `animation.annotationDelay` | Milliseconds between the marks finishing and the annotations starting. |

## Related

- [Animation reference](/docs/spec/animation/) lists every phase setting and its default.
- [Line](/docs/change-over-time/line/) and [Bar](/docs/comparison/bar/) show the entrances these demos play.
- [Scrollytelling](/docs/behavior/scrollytelling/) moves a chart through states with the same update transitions.
