Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

::scroll-button() — CSS scrolling controls

The ::scroll-button() pseudo-element provides a control that scrolls its associated container by one “page”. Its argument selects a direction, content generates the control, and :disabled identifies a scrolling boundary.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

::scroll-button( '*' | <scroll-button-direction> )
<scroll-button-direction> = up | down | left | right | block-start | block-end | inline-start | inline-end | prev | next

::scroll-button() names a pseudo-element family; an empty argument is not a valid selector. The form ::scroll-button( <scroll-button-direction> ) selects one of up to four buttons belonging to a scroll container. A button is generated when its computed content is not none. For a button originating on a non-root element, the button box precedes the container’s box as a sibling rather than appearing inside its scrolling content. For a button originating on the root element, the button box is placed inside the root box instead.

up, down, left, and right are physical directions. block-start, block-end, inline-start, and inline-end depend on writing mode. prev and next select the start and end of the axis with more scrollable pages, comparing overflow size divided by scrollport size. Ties select the block axis.

The newer draft’s grammar, ::scroll-button( '*' | <scroll-button-direction> ), adds ::scroll-button(*) to select all four buttons. Do not quote the asterisk in CSS. The older supplied W3C publication specifies only the directional form; the draft remains subject to change.

Buttons are focusable and activatable by default. Activation scrolls by a “page”, not a guaranteed pixel distance. :disabled matches when further scrolling in that button’s direction is impossible. Locally verify the example in the target browser; retain ordinary scrolling as a fallback.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Scroll buttons</title>
<style>
  .scroller {
    width: 240px;
    height: 100px;
    overflow: auto;
    writing-mode: horizontal-tb;
    direction: ltr;
    border: 1px solid;
  }
  .content {
    height: 500px;
    background: linear-gradient(white, lightblue);
  }
  .scroller::scroll-button(up) { content: "Up"; }
  .scroller::scroll-button(down) { content: "Down"; }
  .scroller::scroll-button(up):disabled,
  .scroller::scroll-button(down):disabled { opacity: 0.4; }
</style>
<div class="scroller" tabindex="0" role="region" aria-label="Scrollable example">
  <div class="content">Start</div>
</div>
</html>

Result

In a supporting browser, Up and Down controls precede the 240px-wide scroller. Initially Up is disabled. Activating Down scrolls downward; at the bottom Down is disabled. The exact distance per activation is browser-dependent.

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources