Scroll area

A scroll area is a box that scrolls on its own, inside the page. No class is needed: the attributes that make it usable are also what style it. A role and a label give it a name, tabindex lets the keyboard reach it, and soft shadows show on any edge with more to see.

A scroll area

Give the box a height to scroll within; the height is a one-off, so it goes inline. Scroll it, or click it or press Tab to reach it and then use the arrow keys. The shadow at the bottom shows there is more below, and one appears at the top once you scroll down.

Day 1

Arrive in the afternoon and walk the old town walls before dinner.

Day 2

Take the morning boat across the lake and climb to the castle.

Day 3

Market in the square, then the long train ride along the coast.

Day 4

A slow breakfast, a last swim and the evening flight home.

<div class="card" role="region" aria-label="Itinerary" tabindex="0" style="max-height: 200px">
  <h3>Day 1</h3>
  <p>Arrive in the afternoon and walk the old town walls before dinner.</p>
  <h3>Day 2</h3>
  <p>Take the morning boat across the lake and climb to the castle.</p>
  …
</div>
A card that scrolls once its content is taller than 200px

Wide content

A table with many columns can be wider than a phone. Wrap it in a scroll area and the table scrolls sideways inside the box, while the page itself stays still. The shadows work on the left and right edges too.

ShopMondayTuesdayWednesdayThursdayFridaySaturdaySunday
High Street9–59–59–59–79–510–4Closed
Market Square8–68–68–68–68–89–510–2
<div role="region" aria-label="Opening hours" tabindex="0">
  <table style="min-width: 1200px">
    <thead>
      <tr><th scope="col">Shop</th><th scope="col">Monday</th> … <th scope="col">Sunday</th></tr>
    </thead>
    <tbody>
      <tr><th scope="row">High Street</th><td>9–5</td> … <td>Closed</td></tr>
      <tr><th scope="row">Market Square</th><td>8–6</td> … <td>10–2</td></tr>
    </tbody>
  </table>
</div>
A wide table that scrolls sideways in its own box

Why the attributes

A box that scrolls has content that cannot be seen until it is scrolled, so everyone has to be able to scroll it. Each attribute does one part of that.

role="region"
Makes the box a landmark, so a screen reader announces it and can jump to it.
aria-label
Names the region. A screen reader reads the name when focus enters the box.
tabindex="0"
Puts the box in the Tab order, so a keyboard user can reach it and scroll it with the arrow keys. Some browsers make a scrolling box focusable on their own; this makes it so in all of them.

The stylesheet keys on the same attributes: any element with role="region" and a tabindex scrolls, shows a focus ring and gets the edge shadows. It also keeps a scroll from running on into the page once the box reaches its end.