Ada LindqvistDesign Engineer

Fading Edges

Horizontal scroll areas have a problem: nothing tells you they scroll. A row of tags or cards that ends exactly at the edge of its container looks complete. People don't swipe what they don't know is there.

The usual fix is a scrollbar, but on most phones and on macOS scrollbars stay hidden until you start scrolling, which is exactly the moment you no longer need the hint.

A soft edge instead

What I use instead is a fade at the edge where more content is waiting. The last visible card dissolves into the background, and that cut-off reads as "there is more over here" without any extra UI.

The simplest version is a mask:

.scroller {
  mask-image: linear-gradient(
    to right,
    black calc(100% - 48px),
    transparent
  );
}

A mask is better than laying a gradient on top, because it works on any background. A gradient overlay has to match the page color exactly, and it breaks the moment the component lands on a card or a tinted section.

Only fade where there is more

A fade on both sides all the time is wrong too. At the start of the list there is nothing to the left, so a fade there just makes the first item look damaged.

So I track the scroll position and only fade the sides that have hidden content:

const atStart = el.scrollLeft <= 0;
const atEnd = el.scrollLeft + el.clientWidth >= el.scrollWidth - 1;
el.dataset.fade = atStart ? "end" : atEnd ? "start" : "both";

Then three mask rules, one for each state. Because the attribute only changes at the two ends, this costs almost nothing while scrolling.

Keep it subtle

The width of the fade matters. Too narrow, around 16px, and it looks like a rendering glitch. Too wide and it eats the content you are trying to show. Somewhere between 32 and 64px works for most card rows, a bit less for a row of small tags.

Nobody will ever notice this detail on purpose. They will just swipe the row, which is the whole point.