# Before and after slider

> Use a before-and-after slider to lay two states of the same picture on top of each other and let readers drag between them.

- Data type: Values over time (`time`)
- Pro · not released yet: its code is not available; try it on its page, or use a free chart of the same data type (`time`)
- Example: **In 2005 one person in six was online; by 2024 it was seven in ten** (Share of people using the internet, by country, 2005 and 2024, %)
- How to read it: Left of the divider is 2005, right of it is 2024; drag the divider across any country to watch it change.
- Interactive: slider
- Phone: Adapts to mobile (Draws its own phone layout below 520px) · Video formats: 16:9 (best 16:9)

## Use it when
- the same map, photo or chart exists in two states
- the change is visible in shape or colour, not only a number
- readers want to scrub back and forth themselves

## Avoid it when
- there are more than two states (use a year slider)
- the change is small and needs exact values (use a dumbbell)
- the two states use different scales

## Fields (data.json)
- `before` (year): the earlier year
- `after` (year): the later year
- `world` (number, unit "%", format percent): world share online in each year, %
- `countries[].id` (id): ISO 3166 numeric code, matches the map
- `countries[].name` (place): the country
- `countries[].before` (number, unit "%", format percent): share online in the earlier year, %
- `countries[].after` (number, unit "%", format percent): share online in the later year, %

Units are the example's: with your own data, set each number field's `unit` and `format` (percent, count, decimal, currency, compact) in the meta you pass to mount, or `chartreuse render --unit field=text --format field=count`. Scales and labels follow your data.

## Interactions, motion, sound
- drag the divider (or the handle) left and right
- the Before and After buttons jump to one side
- hover or tap a country to read both years
- Motion: The divider sweeps once from 2005 to 2024 when the map comes into view, then rests in the middle.
- Sound: A chime at either end. Quiet while it draws and between steps; mute it from its card. (sound is off until the viewer turns it on)

## Example spec
```json
{
  "chart": "before-after-slider",
  "title": "In 2005 one person in six was online; by 2024 it was seven in ten",
  "subtitle": "Share of people using the internet, by country, 2005 and 2024, %",
  "data": "/charts/before-after-slider.data.json"
}
```

## Source
Share of the population using the Internet, Our World in Data (International Telecommunication Union via World Bank) (CC BY 4.0), retrieved 2026-12-01: https://ourworldindata.org/grapher/share-of-individuals-using-the-internet

Note: Countries without figures for both years are left grey.

Live: /charts/before-after-slider · Manifest: /charts/before-after-slider.json · Tags: before and after, swipe, compare, slider, map, internet, technology
