Dev Helpers

CSS / Grid

Build price bands for repeated items

Dev Helpers · November 13, 2025

A price band is useful when an item appears on more than one order line. Group by item before choosing the smallest and largest unit prices.

Worked example

<style>
  dl {
    display: grid;
    gap: 0.6rem;
    margin: 0;
  }
  dl > div {
    display: grid;
    gap: 0.35rem;
    padding: 0.6rem;
    border-bottom: 1px solid #bbb;
  }
  dt {
    font-weight: 700;
  }
  dd {
    margin: 0;
    overflow-wrap: anywhere;
  }
  @media (min-width: 32rem) {
    dl > div {
      grid-template-columns: minmax(5rem, 1fr) 3fr;
    }
  }
</style>
<h2>Build price bands for repeated items</h2>
<dl class="" id="result"></dl>
<script>
  const rows = [
    { item: "tea", units: 2, cents: 350 },
    { item: "mug", units: 1, cents: 900 },
    { item: "tea", units: 3, cents: 325 },
    { item: "tin", units: 2, cents: 500 },
  ];
  const result = Object.fromEntries(
    [...new Set(rows.map((r) => r.item))].map((item) => {
      const prices = rows.filter((r) => r.item === item).map((r) => r.cents);
      return [item, { min: Math.min(...prices), max: Math.max(...prices) }];
    }),
  );
  const list = document.querySelector("#result");
  list.replaceChildren();
  for (const [key, value] of Object.entries(
    typeof result === "object" && result !== null ? result : { value: result },
  )) {
    const row = document.createElement("div");
    const label = document.createElement("dt");
    label.textContent = key;
    const detail = document.createElement("dd");
    detail.textContent =
      typeof value === "string" ? value : JSON.stringify(value);
    row.append(label, detail);
    list.append(row);
  }
  if (!list.children.length) list.after("No matching entries.");
</script>

Implementation notes

A repeated item with one price has a band whose two ends are equal. Decide whether to show a single value or repeat it as a range.

Try it yourself

Add another price for an existing item and inspect just that item's range.

Open the CSS example →

Editorial date November 13, 2025 · Published December 6, 2026

Related articles

Move the grid tracks to the corner

Grid content alignment positions the track group when spare space remains inside the container. Alignment is harder to see when tracks fill all available space.

Fluid width with a maximum

A fluid container needs a small-screen width and a large-screen maximum. Outer gutters should remain visible at both extremes.

Square aspect ratio

A square ratio reserves equal sides even before media loads. Fit rules decide whether rectangular content is cropped or letterboxed.