Skip to content

Scroll Area ​

A native scroll container with custom scrollbars.

Vernacular architecture is building done outside any academic tradition, and without professional guidance. It is not a particular architectural movement or style, but rather a broad category, encompassing a wide range and variety of building types, with differing methods of construction, from around the world, both historical and extant and classical and modern. Vernacular architecture constitutes 95% of the world's built environment, as estimated in 1995 by Amos Rapoport, as measured against the small percentage of new buildings every year designed by architects and built by engineers.

This type of architecture usually serves immediate, local needs, is constrained by the materials available in its particular region and reflects local traditions and cultural practices. The study of vernacular architecture does not examine formally schooled architects, but instead that of the design skills and tradition of local builders, who were rarely given any attribution for the work. More recently, vernacular architecture has been examined by designers and the building industry in an effort to be more energy conscious with contemporary design and construction—part of a broader interest in sustainable design.

vue
<script setup lang="ts">
import { ScrollArea } from '@vase-ui/vue/scroll-area';
import styles from './index.module.css';
</script>

<template>
  <ScrollArea.Root :class="styles.ScrollArea">
    <ScrollArea.Viewport :class="styles.Viewport">
      <ScrollArea.Content :class="styles.Content">
        <p :class="styles.Paragraph">
          Vernacular architecture is building done outside any academic tradition, and without
          professional guidance. It is not a particular architectural movement or style, but rather
          a broad category, encompassing a wide range and variety of building types, with differing
          methods of construction, from around the world, both historical and extant and classical
          and modern. Vernacular architecture constitutes 95% of the world's built environment, as
          estimated in 1995 by Amos Rapoport, as measured against the small percentage of new
          buildings every year designed by architects and built by engineers.
        </p>
        <p :class="styles.Paragraph">
          This type of architecture usually serves immediate, local needs, is constrained by the
          materials available in its particular region and reflects local traditions and cultural
          practices. The study of vernacular architecture does not examine formally schooled
          architects, but instead that of the design skills and tradition of local builders, who
          were rarely given any attribution for the work. More recently, vernacular architecture has
          been examined by designers and the building industry in an effort to be more energy
          conscious with contemporary design and construction—part of a broader interest in
          sustainable design.
        </p>
      </ScrollArea.Content>
    </ScrollArea.Viewport>
    <ScrollArea.Scrollbar :class="styles.Scrollbar">
      <ScrollArea.Thumb :class="styles.Thumb" />
    </ScrollArea.Scrollbar>
  </ScrollArea.Root>
</template>
css
.ScrollArea {
  box-sizing: border-box;
  width: 24rem;
  height: 8.5rem;
  max-width: calc(100vw - 8rem);
  background-color: white;

  @media (prefers-color-scheme: dark) {
    background-color: oklch(14.5% 0 0deg);
  }
}

.Viewport {
  box-sizing: border-box;
  height: 100%;
  border: 1px solid oklch(14.5% 0 0deg);

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
  }

  &:focus-visible {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: -1px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}

.Content {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding-block: 0.5rem;
  padding-left: 0.75rem;
  padding-right: 1.25rem;
}

.Paragraph {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.375rem;
  color: oklch(14.5% 0 0deg);

  @media (prefers-color-scheme: dark) {
    color: white;
  }
}

.Scrollbar {
  display: flex;
  justify-content: center;
  background-color: rgb(0 0 0 / 12%);
  width: 1rem;
  margin: 1px;
  opacity: 0;
  transition: opacity 150ms;
  pointer-events: none;

  @media (prefers-color-scheme: dark) {
    background-color: rgb(255 255 255 / 12%);
  }

  &[data-scrolling] {
    transition-duration: 0ms;
  }

  &[data-scrolling] {
    opacity: 1;
    pointer-events: auto;
  }

  @media (hover: hover) {
    .ScrollArea:hover & {
      opacity: 1;
      pointer-events: auto;
    }
  }
}

.Thumb {
  width: 100%;
  background-color: oklch(14.5% 0 0deg);

  @media (prefers-color-scheme: dark) {
    background-color: white;
  }
}
vue
<script setup lang="ts">
import { ScrollArea } from '@vase-ui/vue/scroll-area';
</script>

<template>
  <ScrollArea.Root
    class="group h-[8.5rem] w-96 max-w-[calc(100vw-8rem)] bg-white dark:bg-neutral-950"
  >
    <ScrollArea.Viewport
      class="h-full border border-neutral-950 dark:border-white focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
    >
      <ScrollArea.Content
        class="flex flex-col gap-4 py-2 pr-5 pl-3 text-sm leading-[1.375rem] text-neutral-950 dark:text-white"
      >
        <p>
          Vernacular architecture is building done outside any academic tradition, and without
          professional guidance. It is not a particular architectural movement or style, but rather
          a broad category, encompassing a wide range and variety of building types, with differing
          methods of construction, from around the world, both historical and extant and classical
          and modern. Vernacular architecture constitutes 95% of the world's built environment, as
          estimated in 1995 by Amos Rapoport, as measured against the small percentage of new
          buildings every year designed by architects and built by engineers.
        </p>
        <p>
          This type of architecture usually serves immediate, local needs, is constrained by the
          materials available in its particular region and reflects local traditions and cultural
          practices. The study of vernacular architecture does not examine formally schooled
          architects, but instead that of the design skills and tradition of local builders, who
          were rarely given any attribution for the work. More recently, vernacular architecture has
          been examined by designers and the building industry in an effort to be more energy
          conscious with contemporary design and construction—part of a broader interest in
          sustainable design.
        </p>
      </ScrollArea.Content>
    </ScrollArea.Viewport>
    <ScrollArea.Scrollbar
      class="m-px flex w-4 justify-center bg-black/12 dark:bg-white/12 opacity-0 transition-opacity pointer-events-none group-hover:opacity-100 group-hover:pointer-events-auto data-scrolling:opacity-100 data-scrolling:duration-0 data-scrolling:pointer-events-auto"
    >
      <ScrollArea.Thumb class="w-full bg-neutral-950 dark:bg-white" />
    </ScrollArea.Scrollbar>
  </ScrollArea.Root>
</template>

Anatomy ​

Import the component and assemble its parts:

vue
<script setup lang="ts">
import { ScrollArea } from '@vase-ui/vue/scroll-area';
</script>

<template>
  <ScrollArea.Root>
    <ScrollArea.Viewport>
      <ScrollArea.Content />
    </ScrollArea.Viewport>
    <ScrollArea.Scrollbar>
      <ScrollArea.Thumb />
    </ScrollArea.Scrollbar>
    <ScrollArea.Corner />
  </ScrollArea.Root>
</template>

Examples ​

Both scrollbars ​

Use <ScrollArea.Corner> so that the two scrollbars do not cross.

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
vue
<script setup lang="ts">
import { ScrollArea } from '@vase-ui/vue/scroll-area';
import styles from './index.module.css';
</script>

<template>
  <ScrollArea.Root :class="styles.ScrollArea">
    <ScrollArea.Viewport :class="styles.Viewport">
      <ScrollArea.Content :class="styles.Content">
        <ul :class="styles.Grid">
          <li v-for="i in 100" :key="i" :class="styles.Item">{{ i }}</li>
        </ul>
      </ScrollArea.Content>
    </ScrollArea.Viewport>
    <ScrollArea.Scrollbar :class="styles.Scrollbar">
      <ScrollArea.Thumb :class="styles.Thumb" />
    </ScrollArea.Scrollbar>
    <ScrollArea.Scrollbar :class="styles.Scrollbar" orientation="horizontal">
      <ScrollArea.Thumb :class="styles.Thumb" />
    </ScrollArea.Scrollbar>
    <ScrollArea.Corner />
  </ScrollArea.Root>
</template>
css
.ScrollArea {
  box-sizing: border-box;
  width: 20rem;
  height: 20rem;
  max-width: calc(100vw - 8rem);
}

.Viewport {
  box-sizing: border-box;
  height: 100%;
  border: 1px solid oklch(14.5% 0 0deg);

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
  }

  &:focus-visible {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: -1px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}

.Content {
  padding: 0.75rem 1.5rem 1.5rem 0.75rem;
}

.Grid {
  display: grid;
  grid-template-columns: repeat(10, 6.25rem);
  grid-template-rows: repeat(10, 6.25rem);
  gap: 0.75rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.Item {
  background-color: oklch(92.2% 0 0deg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  font-weight: 700;
  color: oklch(43.9% 0 0deg);

  @media (prefers-color-scheme: dark) {
    background-color: oklch(26.9% 0 0deg);
    color: oklch(70.8% 0 0deg);
  }
}

.Scrollbar {
  display: flex;
  position: relative;
  background-color: rgb(0 0 0 / 12%);
  margin: 1px;
  opacity: 0;
  transition: opacity 150ms;
  pointer-events: none;

  @media (prefers-color-scheme: dark) {
    background-color: rgb(255 255 255 / 12%);
  }

  &[data-scrolling] {
    transition-duration: 0ms;
  }

  &[data-scrolling] {
    opacity: 1;
    pointer-events: auto;
  }

  @media (hover: hover) {
    .ScrollArea:hover & {
      opacity: 1;
      pointer-events: auto;
    }
  }

  &[data-orientation='vertical'] {
    width: 1rem;
  }

  &[data-orientation='horizontal'] {
    height: 1rem;
  }
}

.Thumb {
  width: 100%;
  background-color: oklch(14.5% 0 0deg);

  @media (prefers-color-scheme: dark) {
    background-color: white;
  }
}
vue
<script setup lang="ts">
import { ScrollArea } from '@vase-ui/vue/scroll-area';
</script>

<template>
  <ScrollArea.Root class="group h-80 w-80 max-w-[calc(100vw-8rem)]">
    <ScrollArea.Viewport
      class="h-full border border-neutral-950 dark:border-white focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
    >
      <ScrollArea.Content class="pt-3 pr-6 pb-6 pl-3">
        <ul
          class="m-0 grid list-none grid-cols-[repeat(10,6.25rem)] grid-rows-[repeat(10,6.25rem)] gap-3 p-0"
        >
          <li
            v-for="i in 100"
            :key="i"
            class="flex items-center justify-center bg-neutral-200 dark:bg-neutral-800 text-sm font-bold text-neutral-600 dark:text-neutral-400"
          >
            {{ i }}
          </li>
        </ul>
      </ScrollArea.Content>
    </ScrollArea.Viewport>
    <ScrollArea.Scrollbar
      class="relative m-px flex bg-black/12 dark:bg-white/12 opacity-0 transition-opacity pointer-events-none data-[orientation=vertical]:w-4 data-[orientation=horizontal]:h-4 group-hover:pointer-events-auto group-hover:opacity-100 data-scrolling:pointer-events-auto data-scrolling:opacity-100 data-scrolling:duration-0"
    >
      <ScrollArea.Thumb class="w-full bg-neutral-950 dark:bg-white" />
    </ScrollArea.Scrollbar>
    <ScrollArea.Scrollbar
      class="relative m-px flex bg-black/12 dark:bg-white/12 opacity-0 transition-opacity pointer-events-none data-[orientation=vertical]:w-4 data-[orientation=horizontal]:h-4 group-hover:pointer-events-auto group-hover:opacity-100 data-scrolling:pointer-events-auto data-scrolling:opacity-100 data-scrolling:duration-0"
      orientation="horizontal"
    >
      <ScrollArea.Thumb class="w-full bg-neutral-950 dark:bg-white" />
    </ScrollArea.Scrollbar>
    <ScrollArea.Corner />
  </ScrollArea.Root>
</template>

Gradient scroll fade ​

Use the overflow CSS variables of the viewport in a CSS mask. The fade then grows as the user scrolls away from an edge.

The server HTML has no value for the variables. A var() with no fallback then makes the mask invalid, and the browser shows no fade. To show the fade before the hydration, give each var() a fallback. Use 0px for the start edge, and the size of the fade for the end edge.

The viewport writes the variables at each scroll, and each element in it inherits them. With thousands of elements in the viewport, the browser can then need some milliseconds in a frame. Register the variables with inherits: false. Then set each variable that a child uses to inherit:

css
@property --scroll-area-overflow-y-start {
  syntax: '<length>';
  inherits: false;
  initial-value: 0px;
}

.Child {
  --scroll-area-overflow-y-start: inherit;
}

Before the measurement, a registered variable has its initial-value, not the fallback of var().

Vernacular architecture is building done outside any academic tradition, and without professional guidance. It is not a particular architectural movement or style, but rather a broad category, encompassing a wide range and variety of building types, with differing methods of construction, from around the world, both historical and extant and classical and modern. Vernacular architecture constitutes 95% of the world's built environment, as estimated in 1995 by Amos Rapoport, as measured against the small percentage of new buildings every year designed by architects and built by engineers.

This type of architecture usually serves immediate, local needs, is constrained by the materials available in its particular region and reflects local traditions and cultural practices. The study of vernacular architecture does not examine formally schooled architects, but instead that of the design skills and tradition of local builders, who were rarely given any attribution for the work. More recently, vernacular architecture has been examined by designers and the building industry in an effort to be more energy conscious with contemporary design and construction—part of a broader interest in sustainable design.

vue
<script setup lang="ts">
import { ScrollArea } from '@vase-ui/vue/scroll-area';
import styles from './index.module.css';
</script>

<template>
  <ScrollArea.Root :class="styles.ScrollArea">
    <ScrollArea.Viewport :class="styles.Viewport">
      <ScrollArea.Content :class="styles.Content">
        <p :class="styles.Paragraph">
          Vernacular architecture is building done outside any academic tradition, and without
          professional guidance. It is not a particular architectural movement or style, but rather
          a broad category, encompassing a wide range and variety of building types, with differing
          methods of construction, from around the world, both historical and extant and classical
          and modern. Vernacular architecture constitutes 95% of the world's built environment, as
          estimated in 1995 by Amos Rapoport, as measured against the small percentage of new
          buildings every year designed by architects and built by engineers.
        </p>
        <p :class="styles.Paragraph">
          This type of architecture usually serves immediate, local needs, is constrained by the
          materials available in its particular region and reflects local traditions and cultural
          practices. The study of vernacular architecture does not examine formally schooled
          architects, but instead that of the design skills and tradition of local builders, who
          were rarely given any attribution for the work. More recently, vernacular architecture has
          been examined by designers and the building industry in an effort to be more energy
          conscious with contemporary design and construction—part of a broader interest in
          sustainable design.
        </p>
      </ScrollArea.Content>
    </ScrollArea.Viewport>
    <ScrollArea.Scrollbar :class="styles.Scrollbar">
      <ScrollArea.Thumb :class="styles.Thumb" />
    </ScrollArea.Scrollbar>
  </ScrollArea.Root>
</template>
css
.ScrollArea {
  box-sizing: border-box;
  width: 24rem;
  height: 12rem;
  max-width: calc(100vw - 8rem);
  background-color: oklch(97% 0 0deg);

  @media (prefers-color-scheme: dark) {
    background-color: oklch(26.9% 0 0deg);
  }

  &:has(.Viewport:focus-visible) {
    outline: 2px solid oklch(14.5% 0 0deg);

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}

.Viewport {
  --fade-size: 40px;
  height: 100%;
  background: oklch(97% 0 0deg);
  mask-image: linear-gradient(
    to bottom,
    transparent 0,
    black min(var(--fade-size), var(--scroll-area-overflow-y-start)),
    black calc(100% - min(var(--fade-size), var(--scroll-area-overflow-y-end, var(--fade-size)))),
    transparent 100%
  );
  mask-repeat: no-repeat;
  outline: none;

  @media (prefers-color-scheme: dark) {
    background: oklch(26.9% 0 0deg);
  }
}

.Content {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding-block: 0.5rem;
  padding-left: 0.75rem;
  padding-right: 1.25rem;
}

.Paragraph {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.375rem;
  color: oklch(14.5% 0 0deg);

  @media (prefers-color-scheme: dark) {
    color: white;
  }
}

.Scrollbar {
  display: flex;
  justify-content: center;
  background-color: rgb(0 0 0 / 8%);
  width: 1rem;
  margin: 1px;
  opacity: 0;
  transition: opacity 150ms;
  pointer-events: none;

  @media (prefers-color-scheme: dark) {
    background-color: rgb(255 255 255 / 12%);
  }

  &[data-scrolling] {
    transition-duration: 0ms;
  }

  &[data-scrolling] {
    opacity: 1;
    pointer-events: auto;
  }

  @media (hover: hover) {
    .ScrollArea:hover & {
      opacity: 1;
      pointer-events: auto;
    }
  }
}

.Thumb {
  width: 100%;
  background-color: oklch(14.5% 0 0deg);

  @media (prefers-color-scheme: dark) {
    background-color: white;
  }
}
vue
<script setup lang="ts">
import { ScrollArea } from '@vase-ui/vue/scroll-area';
</script>

<template>
  <ScrollArea.Root
    class="group h-48 w-96 max-w-[calc(100vw-8rem)] bg-neutral-100 dark:bg-neutral-800 has-[>_:first-child:focus-visible]:outline-2 has-[>_:first-child:focus-visible]:outline-offset-0 has-[>_:first-child:focus-visible]:outline-neutral-950 dark:has-[>_:first-child:focus-visible]:outline-white"
  >
    <ScrollArea.Viewport
      class="h-full bg-neutral-100 dark:bg-neutral-800 outline-none mask-linear-[to_bottom,transparent_0,black_min(40px,var(--scroll-area-overflow-y-start)),black_calc(100%_-_min(40px,var(--scroll-area-overflow-y-end,40px))),transparent_100%] mask-no-repeat"
    >
      <ScrollArea.Content
        class="flex flex-col gap-4 py-2 pr-5 pl-3 text-sm leading-[1.375rem] text-neutral-950 dark:text-white"
      >
        <p>
          Vernacular architecture is building done outside any academic tradition, and without
          professional guidance. It is not a particular architectural movement or style, but rather
          a broad category, encompassing a wide range and variety of building types, with differing
          methods of construction, from around the world, both historical and extant and classical
          and modern. Vernacular architecture constitutes 95% of the world's built environment, as
          estimated in 1995 by Amos Rapoport, as measured against the small percentage of new
          buildings every year designed by architects and built by engineers.
        </p>
        <p>
          This type of architecture usually serves immediate, local needs, is constrained by the
          materials available in its particular region and reflects local traditions and cultural
          practices. The study of vernacular architecture does not examine formally schooled
          architects, but instead that of the design skills and tradition of local builders, who
          were rarely given any attribution for the work. More recently, vernacular architecture has
          been examined by designers and the building industry in an effort to be more energy
          conscious with contemporary design and construction—part of a broader interest in
          sustainable design.
        </p>
      </ScrollArea.Content>
    </ScrollArea.Viewport>
    <ScrollArea.Scrollbar
      class="m-px flex w-4 justify-center bg-black/8 dark:bg-white/12 opacity-0 transition-opacity duration-150 pointer-events-none group-hover:opacity-100 group-hover:pointer-events-auto data-scrolling:opacity-100 data-scrolling:duration-0 data-scrolling:pointer-events-auto"
    >
      <ScrollArea.Thumb class="w-full bg-neutral-950 dark:bg-white" />
    </ScrollArea.Scrollbar>
  </ScrollArea.Root>
</template>

API reference ​

ScrollArea.Root ​

Groups all parts of the scroll area. It hides the native scrollbars of the viewport. With the element slot, the server HTML has no style element, so the native scrollbars show until the mount. Renders a <div> element.

Props

PropTypeDefaultDescription
overflowEdgeThresholdnumber | { xStart?: number | undefined; xEnd?: number | undefined; yStart?: number | undefined; yEnd?: number | undefined; } | undefined0The distance in pixels from an edge within which the edge has no overflow state. A number is for each edge. A missing or negative number is 0.
askeyof HTMLElementTagNameMap | Component | GenericComponent | undefinedA tag or a component that the part renders in place of its own element, with the same attributes and content. The element slot wins over it.

Slots

SlotSlot propsDescription
default
state: ScrollAreaRootState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: ScrollAreaRootState
Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref.

Exposed

MemberTypeDescription
elementHTMLElement | nullThe element of the part, or null while it is not mounted.

Selectors

SelectorDescription
[data-scrolling]The user scrolls, with a wheel, a touch, the keyboard or a drag. It ends 500 ms after the last scroll. A scroll of a script does not count.
[data-has-overflow-x]The content overflows the viewport on the horizontal axis.
[data-has-overflow-y]The content overflows the viewport on the vertical axis.
[data-overflow-x-start]The content overflows the inline start edge.
[data-overflow-x-end]The content overflows the inline end edge.
[data-overflow-y-start]The content overflows the top edge.
[data-overflow-y-end]The content overflows the bottom edge.

CSS variables

VariableDescription
--scroll-area-corner-widthThe width of the corner, in pixels. It is 0px with no corner.
--scroll-area-corner-heightThe height of the corner, in pixels. It is 0px with no corner.

ScrollArea.Viewport ​

The actual scrollable container of the scroll area. It is a native scroll container on the two axes, so the wheel, a touch, the keyboard and scroll snap work as in each browser. It is a tab stop while it can scroll. When it is a landmark of the page, give it role="region" and a name, such as aria-label. Renders a <div> element.

Props

PropTypeDefaultDescription
askeyof HTMLElementTagNameMap | Component | GenericComponent | undefinedA tag or a component that the part renders in place of its own element, with the same attributes and content. The element slot wins over it.

Slots

SlotSlot propsDescription
default
state: ScrollAreaRootState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: ScrollAreaRootState
Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref.

Exposed

MemberTypeDescription
elementHTMLElement | nullThe element of the part, or null while it is not mounted.

Selectors

SelectorDescription
[data-scrolling]The user scrolls, with a wheel, a touch, the keyboard or a drag. It ends 500 ms after the last scroll. A scroll of a script does not count.
[data-has-overflow-x]The content overflows the viewport on the horizontal axis.
[data-has-overflow-y]The content overflows the viewport on the vertical axis.
[data-overflow-x-start]The content overflows the inline start edge.
[data-overflow-x-end]The content overflows the inline end edge.
[data-overflow-y-start]The content overflows the top edge.
[data-overflow-y-end]The content overflows the bottom edge.

CSS variables

VariableDescription
--scroll-area-overflow-x-startThe distance to the inline start edge of the content, in pixels.
--scroll-area-overflow-x-endThe distance to the inline end edge of the content, in pixels.
--scroll-area-overflow-y-startThe distance to the top edge of the content, in pixels.
--scroll-area-overflow-y-endThe distance to the bottom edge of the content, in pixels.

ScrollArea.Content ​

A container for the content of the scroll area. Renders a <div> element.

Props

PropTypeDefaultDescription
askeyof HTMLElementTagNameMap | Component | GenericComponent | undefinedA tag or a component that the part renders in place of its own element, with the same attributes and content. The element slot wins over it.

Slots

SlotSlot propsDescription
default
state: ScrollAreaRootState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: ScrollAreaRootState
Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref.

Exposed

MemberTypeDescription
elementHTMLElement | nullThe element of the part, or null while it is not mounted.

Selectors

SelectorDescription
[data-scrolling]The user scrolls, with a wheel, a touch, the keyboard or a drag. It ends 500 ms after the last scroll. A scroll of a script does not count.
[data-has-overflow-x]The content overflows the viewport on the horizontal axis.
[data-has-overflow-y]The content overflows the viewport on the vertical axis.
[data-overflow-x-start]The content overflows the inline start edge.
[data-overflow-x-end]The content overflows the inline end edge.
[data-overflow-y-start]The content overflows the top edge.
[data-overflow-y-end]The content overflows the bottom edge.

ScrollArea.Scrollbar ​

A vertical or horizontal scrollbar for the scroll area. It lies over the viewport and takes no space. Assistive technology does not read it. It renders while its axis has overflow. To show it at a hover, select :hover of the root. Renders a <div> element.

Props

PropTypeDefaultDescription
keepMountedboolean | undefinedfalseThe scrollbar renders also while its axis has no overflow, in the server HTML too. Hide such a scrollbar with :not([data-has-overflow-y]) or :not([data-has-overflow-x]).
orientation"vertical" | "horizontal" | undefined'vertical'The axis that the scrollbar scrolls.
askeyof HTMLElementTagNameMap | Component | GenericComponent | undefinedA tag or a component that the part renders in place of its own element, with the same attributes and content. The element slot wins over it.

Slots

SlotSlot propsDescription
default
state: ScrollAreaScrollbarState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: ScrollAreaScrollbarState
Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref.

Exposed

MemberTypeDescription
elementHTMLElement | nullThe element of the part, or null while it is not mounted.

Selectors

SelectorDescription
[data-orientation]The axis of the scrollbar: vertical or horizontal.
[data-scrolling]The user scrolls the axis of the scrollbar.
[data-has-overflow-x]The content overflows the viewport on the horizontal axis.
[data-has-overflow-y]The content overflows the viewport on the vertical axis.
[data-overflow-x-start]The content overflows the inline start edge.
[data-overflow-x-end]The content overflows the inline end edge.
[data-overflow-y-start]The content overflows the top edge.
[data-overflow-y-end]The content overflows the bottom edge.

CSS variables

VariableDescription
--scroll-area-thumb-heightThe length of the thumb of a vertical scrollbar, in pixels. It counts the padding of the scrollbar and the margins of the thumb.
--scroll-area-thumb-widthThe length of the thumb of a horizontal scrollbar, in pixels. It counts the padding of the scrollbar and the margins of the thumb.

ScrollArea.Thumb ​

The draggable part of the scrollbar that indicates the current scroll position. It moves with the CSS property translate, so transform stays free for your styles. Give a horizontal thumb equal inline margins: in right-to-left text, the part counts the start margin two times in WebKit. Renders a <div> element.

Props

PropTypeDefaultDescription
askeyof HTMLElementTagNameMap | Component | GenericComponent | undefinedA tag or a component that the part renders in place of its own element, with the same attributes and content. The element slot wins over it.

Slots

SlotSlot propsDescription
default
state: ScrollAreaThumbState
The content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: ScrollAreaThumbState
Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref.

Exposed

MemberTypeDescription
elementHTMLElement | nullThe element of the part, or null while it is not mounted.

Selectors

SelectorDescription
[data-orientation]The axis of the scrollbar: vertical or horizontal.
[data-scrolling]The user scrolls the axis of the thumb.

ScrollArea.Corner ​

A small rectangular area that appears at the intersection of horizontal and vertical scrollbars. It renders while the two axes have overflow. Assistive technology does not read it. Renders a <div> element.

Props

PropTypeDefaultDescription
askeyof HTMLElementTagNameMap | Component | GenericComponent | undefinedA tag or a component that the part renders in place of its own element, with the same attributes and content. The element slot wins over it.

Slots

SlotSlot propsDescription
defaultThe content of the part.
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref.

Exposed

MemberTypeDescription
elementHTMLElement | nullThe element of the part, or null while it is not mounted.

Differences from Base UI ​

Vase UI ports Scroll Area from Base UI 1.9.0.

API ​

Base UIVase UI
ScrollArea.ScrollbarCSS :hover of the root gives the same hook, so the state has no hovering, and the scrollbar has no data-hovering.
ScrollArea.CornerScrollAreaCornerState holds no field, so the corner gives no state and no state type.

Behavior ​

Vase UIEvidence
When two scroll area parts of one kind are mounted, the last one added serves, and the one before it serves again when it leaves. When the corner leaves, the tracks get its width and height back. Base UI reads one ref for each part, and it writes the corner size only while a corner exists.
When the content of a viewport becomes empty and the auto height of the viewport decreases to 0, the root measures the viewport. The parts lose data-has-overflow-y, --scroll-area-overflow-y-end becomes 0px, the scrollbar unmounts and the viewport leaves the tab order. Base UI skips a viewport whose scroll height or scroll width is 0, so it keeps the old overflow, the scrollbar and tabindex=0.

The handbook gives the differences that all components share: Styling, Animation, Composition, Customization, Forms and TypeScript.