# Our World in Data · Choose countries for a life expectancy chart

Search for a country or region in the life expectancy chart’s selector and add it to plot its trend alongside the others. Deselect it to remove just that series.

[Official source](https://ourworldindata.org/grapher/life-expectancy)

## Related motion · Topic Filter

# Topic Filter

Choosing a topic updates both the reading list and its shareable address.

## Try it

Choose a topic, compare the remaining notes, then try the browser's Back button.

## Interaction details

The unfiltered state displays all notes. A topic keeps only matching entries in view.

## Where to use it

Editorial archives and resource collections filtered by subject.

## Implementation prompt

> Include the active topic in the address and restore the matching list on browser navigation.

## Sources and credits

- [Toss Design articles](<https://toss.tech/category/design>)
- [Toss UX Writing filter](<https://toss.tech/category/design?categoryIds=2139>)

## Checking the behavior

The reference stores its selected category in the URL. Here, selecting multiple topics includes every article that matches any selected topic, once per article. Clear the selection to show all. Open the Sound topic to test the empty state. Over HTTP, refresh a filtered URL and use Back after resetting to check restoration.

## Standalone HTML

Save the code below as an HTML file and open it in your browser. The example works offline.

```html
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>Editorial Notes · UI Motion Lab</title>
<style>:root{color-scheme:light;--paper:#f5f3ec;--ink:#262820;--line:#c7c6b7;--accent:#98402b}
*{box-sizing:border-box}body{margin:0;background:var(--paper);color:var(--ink);font:15px/1.55 Arial,'Apple SD Gothic Neo','Malgun Gothic',sans-serif;overflow-wrap:anywhere}
main{width:min(810px,calc(100% - 36px));margin:clamp(20px,5vh,58px) auto}
main h1{margin:0;font-size:clamp(28px,4.1vw,47px);font-weight:700;line-height:1.15;letter-spacing:-.065em}
main>p{color:#56594e;margin:8px 0 22px;line-height:1.55}.panel{padding:clamp(15px,2.7vw,28px);background:#fffdf6;border:1px solid var(--line);border-radius:2px}
button,select,input,textarea{font:inherit}button,select{min-height:40px}button{cursor:pointer}button:disabled{cursor:default;opacity:.45}
button,select{background:#faf9f0;color:inherit;border:1px solid #a6a798;border-radius:3px;padding:5px 12px}
:focus-visible{outline:3px solid #945030;outline-offset:3px}button:enabled:hover,select:hover{border-color:var(--ink)}
[hidden]{display:none!important}.lab-embedded [data-lab-shell]{display:none!important}.lab-embedded main{margin:clamp(12px,2vh,25px) auto}
figure,fieldset{margin:0}p:last-child{margin-bottom:0}fieldset{min-width:0}
@media(max-width:460px){main{width:calc(100% - 24px);margin:16px auto}main>p{font-size:13px;margin:5px 0 14px}main h1{font-size:26px}.panel{padding:13px}}
@media(prefers-reduced-motion:reduce){*,*::before,*::after{animation-duration:.01ms!important;transition-duration:.01ms!important;scroll-behavior:auto!important}}
.lab-reduce *,.lab-reduce *::before,.lab-reduce *::after{animation-duration:.01ms!important;transition-duration:.01ms!important;scroll-behavior:auto!important}
.panel{background:#fbf7ec;border-top:3px solid #514b3e}
fieldset{border:0;padding:0;display:flex;flex-wrap:wrap;gap:5px}legend{margin:0 0 7px;font-size:13px;font-weight:650}
fieldset label{display:inline-flex;align-items:center;gap:5px;padding:6px 10px;border:1px solid #a8a28e;cursor:pointer;font-size:13px;color:#494838}
fieldset label:has(:checked){background:#424d3e;color:#fff;border-color:#424d3e}input{accent-color:#465c46}
.filter-summary{display:flex;align-items:center;justify-content:space-between;gap:12px;margin:12px 0 0;color:#615b4e;font-size:12px}.filter-summary p{margin:0}.filter-summary button{padding:4px 0;background:none;border:0;text-decoration:underline;text-underline-offset:3px;min-height:32px}
#notes{margin:2px 0 0;padding:0;list-style:none}#notes li{display:flex;align-items:center;gap:clamp(10px,2.6vw,22px);border-top:1px solid var(--line);padding:10px 0}
.note-thumb{width:clamp(62px,11vw,100px);aspect-ratio:1.6;height:auto;object-fit:cover;flex-shrink:0;background:#e2d7bd}.letter{display:grid;place-items:center;color:#766036;font:italic 35px/1 Georgia,serif;background:repeating-linear-gradient(90deg,#efe5ce 0 9px,#ddd2b7 9.5px 10px)}
#notes small{display:block;color:#655d4a;font-size:10px}#notes strong{display:block;font-size:clamp(15px,2vw,21px);letter-spacing:-.045em}#notes li p{margin:1px 0 0;font-size:12px;color:#58574c}
</style>
<script>
const viewOptions=new URLSearchParams(location.search);
document.documentElement.classList.toggle('lab-embedded',viewOptions.get('embed')==='1');
document.documentElement.classList.toggle('lab-reduce',viewOptions.get('reduce')==='1');
</script>
</head>
<body class="lab-example">
<main><h1>Editorial Notes</h1><p>Select a topic to filter the notes. The URL reflects your selection.</p>
<section class="panel" aria-label="Find notes">
 <fieldset><legend>Choose topic</legend>
 <label><input type="checkbox" value="print"> Print</label>
 <label><input type="checkbox" value="type"> Type</label>
 <label><input type="checkbox" value="photo"> Photography</label>
 <label><input type="checkbox" value="sound"> Sound</label></fieldset>
 <div class="filter-summary"><p role="status" id="results"></p><button type="button" id="reset">Clear selection</button></div>
 <ul id="notes">
 <li data-tags="print type"><span class="note-thumb letter" aria-hidden="true">Aa</span><div><small>Print · Type</small><strong>Matching type to paper grain</strong><p>Choosing a type weight for paper that lets halftone ink spread.</p></div></li>
 <li data-tags="photo"><img class="note-thumb" src="data:image/webp;base64,UklGRjQOAABXRUJQVlA4ICgOAAAQOgCdASrAAHIAPl0okEWjoqGVCZ2gOAXEsRnFEoqtKvaZNkevnmgfg+cNZ/8L+POVZOd3Oz2/0d7A/Px8yH7Vfqr7znpL/wnqAf3n+NdcL6AHl0ez9+6PpVVmXqTHbLAYAT7dzonWq49AD81+jBoL+pvYO8tL2Rfs57Tv7MnqBaK3GWwSzxsxR5FccYHraP/axVmRqGtkxZbR/SAquW0mBLhwUCF9bPP2lAVQxJ1SVHq/vCnY8+62kwet64pAcJ9iDmnMkFH9eqef8Q1heK77G88LIBMtNC5MkrQ2JHSPaIW9vIDoi5ZT3H3ezXaVUpgnczwOaaxNfUqg0uqY/PvTl0zc8DmWDJ4IZMhcEUbtzCuSF+t90NYz0HsxlTKCLZSjnilKuK17+B4XJRUvdB1Tdfnh+2+Gv/BGCkTs2IjW1z/KIv5jgXHmODJ2kUcuge80QdgycbbSueJxMcaZlCf6QZ9sVepDoguFcOzbMnhN8+Et59zu/Jq5/4Igsf3+30q5O/2CzNNquIXCdYnPY3DDBziL4026b5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ography</small><strong>Recording shadows on a small object</strong><p>Light direction and texture on a red paper sculpture.</p></div></li>
 <li data-tags="print"><img class="note-thumb" src="data:image/webp;base64,UklGRrIGAABXRUJQVlA4IKYGAABwJACdASrAAHIAPl0qkkajoiIkpxJKcJALiUAZ5MwsB9IPzP9F5+PlWZe+t5u9AnoT/SPohdIbzAecr6VP+L6gH+A6l70AOlsYCA9W6ozs/1FjMNO8obM3yuGUn+Ft+/w7GlqeALp3hgTn3/23Gt7AWVJg3VJNfPUdqMmy+vPEvt9LZEygINRG3BZt5aE441hYmvbj7LrZYjop57mAhtI2JAyxoyd6995N1TKeOrWSxQ5m9+Gcb85DTbAlgPKeGL/CCuYzh+lTlL1d3f07RodGL2lqq16G6UkOX4aDFozg1DmRMNUmD87un/rwE/bvU6GlAvvBg8cXYK0dNyp/RjryBbXt6hjpxjCGOLVqFtXHFhiUTK0zscK0jqMQ5mIFCkh/8pOkTqrQtayvLgAA/vtMY+axGFu7nCviquACpyDIJf772POVE+g6FdXptu9beqR9vbpVD0quVbLEFtHT5yj2CZJD7sma/WVPqE3E8/DOsapEFiAObqxEKH7EBDXHS9rZ+EFJiCCNAB2VGTP3udcEmk0ZvaqsGRbcTA+cOLa7TjNdDunhf7zoRuswPbQy1RP9OqTOd6PgWDqT6EtTDzTfv100uoYgC6G4jepFsMGQG7jOmKwVsaHBPtxV24EE8A2xL/NZ9wAXBUAJH2Pzu41YDWUK1u+pzvTKdjhy9Ab2DVjbVUJpY9tHJ7Pje/8tn8ZiUG/ss6qyr4m/M/Yvh3UudUXHZ6qGJw2iw3pd01+Z6FQmWmzTZUvcTWgZj7AJ+dy73atl3yvw5g1dO9IvQAd762xrzeKgVeDHvcwLpaCntUoemiJ4tnOrmIqJ47ykqQJTHWEkal5EwtUBfGMKrwCuNY1DAGfSjxjC1ORdlzP/tdAA1xpcLRGCpy2UmNA3bYQbwjWu1qf137FVzI5zYApTaXtP3LOKwar6BRzI+wRPmamXr9rlCBOE3fCMoy9DKX+bpci3d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Zk6sOvoXEQNLow/iLpUlH0H9vcAfbXxtyAMRfZ+gpwYHC6ygZEBDebF4vSta6HFLxo9E0doZ2TCTzmSDYROsT7fRJlJSI4eNW76WvRbhv77MsxcmsTdLweU6nEcgoEdIj+avQRjNRx7rtBTWxLV4gxVI1ybMpGuTZ2R+2pqhudodeowj+x/b12zjpJ+S+YSsPhqvazjA6yl6T3PsqQySQwux2GF9AAAAA" alt="" width="96" height="57"><div><small>Print</small><strong>Checking the second proof</strong><p>Comparing colors where the teal ridge overlaps the sun.</p></div></li>
 </ul></section>
</main>
<script>

const options = Array.from(document.querySelectorAll("fieldset input"));
const notes = Array.from(document.querySelectorAll("#notes li"));
const reset = document.querySelector("#reset");
function show(persist) {
  const selected = options.filter(option => option.checked).map(option => option.value);
  for (const note of notes) {
    const topics = note.dataset.tags.split(" ");
    note.hidden = selected.length > 0 && !selected.some(topic => topics.includes(topic));
  }
  const count = notes.filter(note => !note.hidden).length;
  document.querySelector("#results").textContent = count ? count + (count === 1 ? " note" : " notes") : "No notes for this topic. Try a different one.";
  reset.disabled = selected.length === 0;
  if (!persist || !/^https?:$/.test(location.protocol)) return;
  const url = new URL(location.href);
  url.searchParams.delete("topic");
  selected.forEach(topic => url.searchParams.append("topic", topic));
  if (url.href !== location.href) history.pushState(null, "", url);
}
function restore() {
  const selected = new URL(location.href).searchParams.getAll("topic");
  options.forEach(option => { option.checked = selected.includes(option.value); });
  show(false);
}
options.forEach(option => option.addEventListener("change", () => show(true)));
reset.addEventListener("click", () => {
  options.forEach(option => { option.checked = false; });
  options[0].focus();
  show(true);
});
window.addEventListener("popstate", restore);
restore();
</script>
</body></html>
```
