A shopping cart interaction can be built so that clicking a product moves it straight into the cart, with a smooth transition showing the trip and no practical cap on how many items you add. The core logic is CSS, apart from the selected-item counter, and it rests on pairs of radio inputs declared in the markup — a design its author calls "infinite selection," metaphorically speaking.

The approach is presented as one option among several, with its own caveats that the author addresses directly.

How each product is structured

Every item is a wrapper holding two radio inputs that share the same name value, forming a radio group. Checking one input in the pair automatically unchecks the other, so the two see-saw between checked and unchecked regardless of which one is clicked.

<div class="items flat-white">
  <input type="radio" name="r3" title="Flat White">
  <input type="radio" name="r3" title="Flat White">
</div>

Both the wrapper and its inputs are absolutely positioned, and inset stretches the inputs across the full area so every part of the item is clickable, with no dead zones.

.items {   
  position: absolute;

  input { 
    position: absolute; 
    inset: 0; 
  }
}

Laying out the items

The items are placed around a centered cart using translate, moving each from the cart's central point outward to a slightly higher, spread position. Any layout works as long as selected radio buttons can reach the cart. The catch is a bit of magic numbering to tune positions for a given use case — something the author suggests another approach might abstract away.

.items {
  --y: 100px; /* Vertical distance from the cart */

  &:not(.cart) {
    transform: translate(var(--x), calc(-1 * var(--y)));
  }
  &.espresso { 
    --x: 0px;  /* Horizontal dist. from the cart */
  }
  &.cappuccino { 
    --x: -100%; 
  }
  &.flat-white { 
    --x: 100%; 
  }
}

Moving a selection into the cart

When an item's input is :checked, the styles shrink it and translate it to the cart's location.

input:checked {
  transform: translate(calc(-1 * var(--x)), var(--y)) scale(0);
}

The mechanism takes advantage of the shared name: checking the second radio in a group immediately unchecks the first, providing boolean-style state changes akin to the Checkbox Hack, which in turn drives the transition. A transition is required, otherwise the item jumps to the cart instantly with no visible movement.

input:checked{
  transform: translate(calc(-1 * var(--x)), var(--y)) scale(0);
  transition: transform .6s linear;
}

The demo has no separate cart page; instead, an <output> element shows how many items have been added, incrementing a count on each radio click and displaying it as a label on the cart icon. Removing items is not supported, so once added they stay.

let n = 0;
const CART_CNT = document.querySelector("output");
document.querySelectorAll("[type='radio']").forEach(radio => {
  radio.onclick = () => {
    CART_CNT.innerText = ++n;
    CART_CNT.setAttribute("arial-label", `${n}`)
  }
});

Accessibility trade-offs

The author is candid that the duplicated interactive elements make consistent screen reader output hard to guarantee. Because each group contains two interactive elements, assistive technology may announce one input when toggling into an item and the other when toggling back; in other cases both inputs are announced, implying multiple options in a group that really has one.

Mitigations in the demo: a hidden <span> in the markup that surfaces as instruction during keyboard interaction, and an aria-label on the <output> that announces the running total of cart items.

Alternatives

The author points to the modern View Transition API as a likely fit, citing Adrian Bece's Smashing Magazine article, whose example animates items added to a shopping cart. That route needs only two elements — the item and the cart label — connected with a view-transition-name, moved via an @keyframes animation, and triggered on click, with no duplicate elements or state juggling.

For a small, fixed set of items, a single checkbox input per item is another option, though it limits how many items can be added. The radio approach remains worth considering when an effectively unlimited number of items is needed and the View Transition API is out of scope.