# Responsive

> How a chart re-lays out from phone to desktop: the compact, medium and full breakpoints and the responsive settings.

A chart lays itself out again for the width it gets. These three figures are the same spec at full article width, at 560px and at 360px, the width of a phone.

```json
{
  "mark": {
    "type": "line",
    "strokeWidth": 2.5
  },
  "chromeLayout": "subtract",
  "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
    },
    {
      "date": "2022-01-01",
      "rate": 7.5
    },
    {
      "date": "2022-04-01",
      "rate": 8.3
    },
    {
      "date": "2022-07-01",
      "rate": 8.5
    },
    {
      "date": "2022-10-01",
      "rate": 7.7
    },
    {
      "date": "2023-01-01",
      "rate": 6.4
    },
    {
      "date": "2023-04-01",
      "rate": 4.9
    },
    {
      "date": "2023-07-01",
      "rate": 3.2
    },
    {
      "date": "2023-10-01",
      "rate": 3.2
    },
    {
      "date": "2024-01-01",
      "rate": 3.1
    },
    {
      "date": "2024-04-01",
      "rate": 3.4
    },
    {
      "date": "2024-07-01",
      "rate": 2.9
    },
    {
      "date": "2024-10-01",
      "rate": 2.6
    }
  ],
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal"
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "Year-over-year change (%)",
        "format": ".0f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "2022-07-01",
      "y": 8.5,
      "text": "Peak: 8.5%",
      "anchor": "top",
      "offset": {
        "dx": 0,
        "dy": -16
      },
      "connector": true
    },
    {
      "type": "text",
      "x": "2020-04-01",
      "y": 0.3,
      "text": "Pandemic low: 0.3%",
      "anchor": "right",
      "offset": {
        "dx": 12,
        "dy": 0
      },
      "connector": true
    },
    {
      "type": "refline",
      "y": 2,
      "label": "Fed target, 2%",
      "style": "dashed"
    }
  ],
  "chrome": {
    "title": "US inflation went from 0.3% in 2020 to a peak of 8.5% in 2022",
    "subtitle": "Consumer price index, year-over-year change, %, quarterly 2019–2024"
  }
}
```

```json
{
  "mark": {
    "type": "line",
    "strokeWidth": 2.5
  },
  "chromeLayout": "subtract",
  "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
    },
    {
      "date": "2022-01-01",
      "rate": 7.5
    },
    {
      "date": "2022-04-01",
      "rate": 8.3
    },
    {
      "date": "2022-07-01",
      "rate": 8.5
    },
    {
      "date": "2022-10-01",
      "rate": 7.7
    },
    {
      "date": "2023-01-01",
      "rate": 6.4
    },
    {
      "date": "2023-04-01",
      "rate": 4.9
    },
    {
      "date": "2023-07-01",
      "rate": 3.2
    },
    {
      "date": "2023-10-01",
      "rate": 3.2
    },
    {
      "date": "2024-01-01",
      "rate": 3.1
    },
    {
      "date": "2024-04-01",
      "rate": 3.4
    },
    {
      "date": "2024-07-01",
      "rate": 2.9
    },
    {
      "date": "2024-10-01",
      "rate": 2.6
    }
  ],
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal"
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "Year-over-year change (%)",
        "format": ".0f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "2022-07-01",
      "y": 8.5,
      "text": "Peak: 8.5%",
      "anchor": "top",
      "offset": {
        "dx": 0,
        "dy": -16
      },
      "connector": true
    },
    {
      "type": "text",
      "x": "2020-04-01",
      "y": 0.3,
      "text": "Pandemic low: 0.3%",
      "anchor": "right",
      "offset": {
        "dx": 12,
        "dy": 0
      },
      "connector": true
    },
    {
      "type": "refline",
      "y": 2,
      "label": "Fed target, 2%",
      "style": "dashed"
    }
  ],
  "chrome": {
    "title": "US inflation went from 0.3% in 2020 to a peak of 8.5% in 2022",
    "subtitle": "Consumer price index, year-over-year change, %, quarterly 2019–2024"
  }
}
```

```json
{
  "mark": {
    "type": "line",
    "strokeWidth": 2.5
  },
  "chromeLayout": "subtract",
  "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
    },
    {
      "date": "2022-01-01",
      "rate": 7.5
    },
    {
      "date": "2022-04-01",
      "rate": 8.3
    },
    {
      "date": "2022-07-01",
      "rate": 8.5
    },
    {
      "date": "2022-10-01",
      "rate": 7.7
    },
    {
      "date": "2023-01-01",
      "rate": 6.4
    },
    {
      "date": "2023-04-01",
      "rate": 4.9
    },
    {
      "date": "2023-07-01",
      "rate": 3.2
    },
    {
      "date": "2023-10-01",
      "rate": 3.2
    },
    {
      "date": "2024-01-01",
      "rate": 3.1
    },
    {
      "date": "2024-04-01",
      "rate": 3.4
    },
    {
      "date": "2024-07-01",
      "rate": 2.9
    },
    {
      "date": "2024-10-01",
      "rate": 2.6
    }
  ],
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal"
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "Year-over-year change (%)",
        "format": ".0f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "2022-07-01",
      "y": 8.5,
      "text": "Peak: 8.5%",
      "anchor": "top",
      "offset": {
        "dx": 0,
        "dy": -16
      },
      "connector": true
    },
    {
      "type": "text",
      "x": "2020-04-01",
      "y": 0.3,
      "text": "Pandemic low: 0.3%",
      "anchor": "right",
      "offset": {
        "dx": 12,
        "dy": 0
      },
      "connector": true
    },
    {
      "type": "refline",
      "y": 2,
      "label": "Fed target, 2%",
      "style": "dashed"
    }
  ],
  "chrome": {
    "title": "US inflation went from 0.3% in 2020 to a peak of 8.5% in 2022",
    "subtitle": "Consumer price index, year-over-year change, %, quarterly 2019–2024"
  }
}
```

## Breakpoints

The library sorts every chart into one of three breakpoints by the width of its container, and each breakpoint has its own layout rules:

| Breakpoint | Width | What changes |
| --- | --- | --- |
| Full | over 700px | Every value label, full axis ticks, callouts inline. |
| Medium | 400 to 700px | The most important labels, fewer ticks. |
| Compact | under 400px | No value labels, the fewest ticks, at most one inline callout. |

At 360px the phone figure keeps one callout in place and turns the other into a numbered marker, with its text in a note under the plot. Height counts too: a chart 350px tall or less keeps its title and drops the subtitle, and one under 100px hides both.

`overrides` replaces parts of the spec at one breakpoint: the title and subtitle, labels, legend, annotations, or an axis or scale setting. `overrides: { compact: { annotations: [] } }` removes the callouts on phones only.

## Keeping the last date

```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 (%)",
        "format": ".0f",
        "grid": true
      }
    },
    "color": {
      "field": "source",
      "type": "nominal"
    }
  },
  "endpointLabels": {
    "format": ".0f"
  },
  "chromeLayout": "subtract",
  "responsive": {
    "preserveEnd": true,
    "labelSummary": true
  },
  "chrome": {
    "title": "Wind has generated more US electricity than hydro every year since 2019",
    "subtitle": "Share of generation from the six main sources, %, 2016–2023"
  }
}
```

At compact width the x axis thins its ticks and can drop the last year, which on a time series is often the one the reader wants. `responsive: { preserveEnd: true }` keeps the final tick and thins the ones before it instead.

This chart also sets `labelSummary: true`, a fallback for the names at the right edge. Here all six still fit; when they cannot, the library moves the names and last values into a keyed list under the plot, so every series stays named.

## More callouts on a phone

```json
{
  "mark": {
    "type": "line",
    "strokeWidth": 2.5
  },
  "chromeLayout": "subtract",
  "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
    },
    {
      "date": "2022-01-01",
      "rate": 7.5
    },
    {
      "date": "2022-04-01",
      "rate": 8.3
    },
    {
      "date": "2022-07-01",
      "rate": 8.5
    },
    {
      "date": "2022-10-01",
      "rate": 7.7
    },
    {
      "date": "2023-01-01",
      "rate": 6.4
    },
    {
      "date": "2023-04-01",
      "rate": 4.9
    },
    {
      "date": "2023-07-01",
      "rate": 3.2
    },
    {
      "date": "2023-10-01",
      "rate": 3.2
    },
    {
      "date": "2024-01-01",
      "rate": 3.1
    },
    {
      "date": "2024-04-01",
      "rate": 3.4
    },
    {
      "date": "2024-07-01",
      "rate": 2.9
    },
    {
      "date": "2024-10-01",
      "rate": 2.6
    }
  ],
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal"
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "Year-over-year change (%)",
        "format": ".0f",
        "grid": true
      }
    }
  },
  "annotations": [
    {
      "type": "text",
      "x": "2022-07-01",
      "y": 8.5,
      "text": "Peak: 8.5%",
      "anchor": "top",
      "offset": {
        "dx": 0,
        "dy": -16
      },
      "connector": true
    },
    {
      "type": "text",
      "x": "2020-04-01",
      "y": 0.3,
      "text": "Pandemic low: 0.3%",
      "anchor": "right",
      "offset": {
        "dx": 12,
        "dy": 0
      },
      "connector": true
    },
    {
      "type": "refline",
      "y": 2,
      "label": "Fed target, 2%",
      "style": "dashed"
    }
  ],
  "chrome": {
    "title": "US inflation went from 0.3% in 2020 to a peak of 8.5% in 2022",
    "subtitle": "Consumer price index, year-over-year change, %, quarterly 2019–2024"
  },
  "responsive": {
    "compactAnnotationLimit": 2
  }
}
```

`responsive: { compactAnnotationLimit: 2 }` lets both callouts stay inline below 400px. The default is one. Set `null` for no limit, which suits callouts short enough to fit side by side. A callout that would overlap another still becomes a numbered note.

## Fields that matter

| Field | What it does |
| --- | --- |
| `responsive` | An object of the options below. |
| `responsive.preserveEnd` | Keeps the final tick on a time axis when ticks are thinned. |
| `responsive.labelSummary` | Moves end labels into a list under the plot when they cannot fit. |
| `responsive.compactAnnotationLimit` | Inline callouts allowed below 400px. Default 1; `null` for no limit. |
| `responsive.autoThin` | `true` by default: overlapping callouts become numbered notes. `false` hides them at compact width. |
| `overrides` | Chrome, labels, legend, annotations and axis settings for one breakpoint: `compact`, `medium` or `full`. |

## Related

- [Line](/docs/change-over-time/line/) covers the chart type on this page.
- [Annotations](/docs/framing/annotations/) explains the callouts that thin at compact width.
- [ChartSpec reference](/docs/spec/chart-spec/) lists `responsive` and `overrides`.
