Semantic Content Grouping

<figure> groups a piece of self-contained content (image, chart, code block, quote) with its caption — so the browser knows they belong together, even if the figure is floated to the side.

Code block in a figure

// Debounce utility — returns a function that delays
// invoking fn until after wait ms have elapsed since last call.
function debounce(fn, wait) {
  let t;
  return (...args) => {
    clearTimeout(t);
    t = setTimeout(() => fn(...args), wait);
  };
}
Listing 3: debounce — prevents rapid-fire event handlers from triggering work on every keystroke.

Why not just use a <div>? Screen readers announce "figure" as a landmark and associate the <figcaption> with it. Search engines also use captions for image indexing.