Skip to content

shadcn.io is an independent project built on shadcn/ui

Components

Free

Scroll Area for Solid

A box of fixed height that scrolls its own content, for a tag list, a chat log or a strip of photos, with a thin scrollbar. For Solid on Ark UI.

On this page9 sections
UI library: Ark UI

A scroll area is a box with a set height or width that scrolls its own content, so a long list stays inside a sidebar, a popover or a card instead of stretching the page. It suits a tag list, a chat log or a row of thumbnails.

When the items should snap one at a time and come with previous and next buttons, use a Carousel.

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

Anatomy

Scroll Area anatomy: root, viewport, content, scrollbar, thumb

Usage

import { ScrollArea } from "@/components/ui/scroll-area";

The height on ScrollArea is what makes it scroll. Its content can be any length.

const tags = Array.from({ length: 50 }, (_, i) => `v1.2.0-beta.${50 - i}`);

const Tags = () => (
  <ScrollArea class="h-72 w-48 rounded-md border">
    <div class="p-4">
      <h4 class="mb-4 font-medium text-sm leading-none">Tags</h4>
      {tags.map((tag) => (
        <div class="border-b py-2 text-sm last:border-0" key={tag}>
          {tag}
        </div>
      ))}
    </div>
  </ScrollArea>
);

Accessibility

This Scroll Area hides the browser's scrollbar and draws its own, which takes no focus. The scrolling box joins the tab order whenever its content overflows, one way or both, and draws a ring inside its edge while it has keyboard focus, so keyboard users can Tab in and scroll with the keys below. The box has no role or name of its own, so when it holds a whole section of the page, such as a chat log, put a heading above it.

Tab
Moves focus to the scrolling box when it is in the tab order, then on to the links and buttons inside it.
Arrow Down
When the box has focus, scrolls it down a short step.
Arrow Up
When the box has focus, scrolls it up a short step.
Arrow Right
When the box has focus and its content is wider than it, scrolls right.
Arrow Left
When the box has focus and its content is wider than it, scrolls left.
Page Down
When the box has focus, scrolls down by about the height of the box.
Page Up
When the box has focus, scrolls up by about the height of the box.
Home
When the box has focus, scrolls to the top.
End
When the box has focus, scrolls to the bottom.

Demos

Horizontal

Three photos with their photographers' names sit in one row that doesn't wrap, w-max inside a box w-96 wide, so the extra width becomes the scroll range. The area renders a horizontal bar beside the vertical one and shows each only when its axis overflows, so nothing is added for it. Use it for a strip of thumbnails or logos that must stay one row tall.

Preview width

RTL

The tag list again, with an Arabic heading and dir set to rtl on the area, so the heading and rows align right and the scrollbar sits on the left edge. The attribute mirrors the area through CSS, while Ark UI reads the direction only from a Direction provider, which a horizontal area needs to place its thumb. Use it for an Arabic or Hebrew interface.

Preview width

FAQ

Why won't my Scroll Area scroll?

A Scroll Area scrolls only when its own box is shorter than its content, so it needs a height that doesn't come from the content: a class such as h-72, as the demo has, or h-full inside a parent whose height is set.

The area is size-full with min-h-0 already, so inside a parent with a set height, a flex column included, it fills that parent and scrolls with no class of its own. If the parent's height comes from its content, nothing is left to scroll.

How do I give a Scroll Area a max height instead of a fixed one?

Put the class on ScrollArea, such as max-h-72. The area then stays as short as its content and starts to scroll once it reaches the limit, which suits a dropdown of results or a comment thread whose length you don't know in advance.

The area is a flex column, and the viewport inside it, the box that actually scrolls, may shrink below its content, so it stops at the area's limit instead of growing past it.

How do I make a Scroll Area scroll horizontally?

Make the content wider than the area and keep it from wrapping: a row with w-max, and whitespace-nowrap on the area, as the Horizontal demo does.

The area already renders a horizontal bar beside the vertical one and shows each only when its axis overflows, so there is nothing to add.

How do I keep the Scroll Area scrollbar always visible?

Remove opacity-0 from the classes of ScrollAreaScrollbar in components/ui/scroll-area. As shipped, the bars stay transparent until the pointer is over the area or it scrolls, which the data-hover and data-scrolling attributes mark, and fade out again 300ms after that ends.

How do I change the color of the Scroll Area scrollbar?

Edit ScrollAreaScrollbar in components/ui/scroll-area, which is your code once installed. The thumb is bg-foreground/8, darkening to bg-foreground/12 on hover, and w-1 thick, growing to w-1.5, so change those classes for another color or weight. Set scrollFade to true on ScrollArea to also fade the top and bottom edges while there is more to scroll.

How do I scroll a Scroll Area to the bottom when a new message arrives?

From a component rendered inside ScrollArea, call useScrollArea and then its scrollToEdge with { edge: "bottom" } once the new message has rendered. The same object's isAtBottom reports whether the viewport is scrolled to the end.

Scroll only when the reader was already at the end, so someone who moved up to an older message isn't pulled back down. A chat log, a build output and an activity feed all want that exception.

Should I use a Scroll Area or plain CSS overflow?

Use Scroll Area when the bar should look the same in every browser: it hides the native scrollbar and draws a thin themed one that sits over the content instead of taking width from it. Plain overflow-y-auto is enough when the platform's own bar is fine, and it runs no JavaScript, while this component measures the content to size and place its thumb.

Neither one touches the page's own scrollbar. A Scroll Area styles the bar of its own box, and the window keeps the browser's.

Does a Scroll Area work in a right-to-left layout?

Yes. Set dir to rtl on ScrollArea, as the RTL demo does, and the area mirrors through CSS: its content reads right to left and the vertical bar moves to the left edge. Without it, Ark UI writes dir="ltr" on the area's root, so its content reads left to right even on a right-to-left page.

A horizontal area also needs a Direction provider around it, because Ark UI reads the direction only from the provider when it places the horizontal thumb and marks which edge the content is scrolled to.

API Reference

ScrollArea

<div> data-slot="scroll-area"

PropType
dir?"ltr" | "rtl"

The document's text/writing direction.

Type
"ltr" | "rtl"
Default
"ltr"
id?string

The unique identifier of the machine.

ids?object

The ids of the scroll area elements.

Type
{ root?: string; viewport?: string; content?: string; scrollbar?: string; thumb?: string }
scrollFade?boolean

Fades the content out at the edges it can still scroll to.

Default
false
asChild?(props: ParentProps) => JSX.Element

Render your own element: a function that gets the part's props to spread on it.

Type
(props: ParentProps) => JSX.Element
class?string

Merged with the part's classes.

AttributeType
data-overflow-x?string

Present when the content overflows the x-axis.

data-overflow-y?string

Present when the content overflows the y-axis.

CSS variableType
--corner-heightstring

The height of the Root.

--corner-widthstring

The width of the Root.

--thumb-heightstring

The height of the slider thumb.

--thumb-widthstring

The width of the slider thumb.

ScrollAreaContent

<div> data-slot="scroll-area-content"

PropType
asChild?(props: ParentProps) => JSX.Element

Render your own element: a function that gets the part's props to spread on it.

Type
(props: ParentProps) => JSX.Element
AttributeType
data-overflow-x?string

Present when the content overflows the x-axis.

data-overflow-y?string

Present when the content overflows the y-axis.

ScrollAreaScrollbar

<div> data-slot="scroll-area-scrollbar"

PropType
orientation?"horizontal" | "vertical"

The axis it scrolls: horizontal or vertical.

Type
"horizontal" | "vertical"
asChild?(props: ParentProps) => JSX.Element

Render your own element: a function that gets the part's props to spread on it.

Type
(props: ParentProps) => JSX.Element
class?string

Merged with the part's classes.

AttributeType
data-dragging?string

Present when in the dragging state.

data-hover?string

Present when hovered.

data-orientation?string

The orientation of the scrollbar.

data-overflow-x?string

Present when the content overflows the x-axis.

data-overflow-y?string

Present when the content overflows the y-axis.

data-scrolling?string

Present when scrolling.

ScrollAreaThumb

<div> data-slot="scroll-area-thumb"

PropType
asChild?(props: ParentProps) => JSX.Element

Render your own element: a function that gets the part's props to spread on it.

Type
(props: ParentProps) => JSX.Element
AttributeType
data-dragging?string

Present when in the dragging state.

data-hover?string

Present when hovered.

data-orientation?string

The orientation of the thumb.

ScrollAreaCorner

<div> data-slot="scroll-area-corner"

PropType
asChild?(props: ParentProps) => JSX.Element

Render your own element: a function that gets the part's props to spread on it.

Type
(props: ParentProps) => JSX.Element
AttributeType
data-hover?string

Present when hovered.

data-overflow-x?string

Present when the content overflows the x-axis.

data-overflow-y?string

Present when the content overflows the y-axis.

data-ownedbystring

Id of the root part.

data-state"hidden" | "visible"

"hidden" or "visible".

Type
"hidden" | "visible"

useScrollArea

PropType
id?string

The unique identifier of the machine.

ids?object

The ids of the scroll area elements.

Type
{ root?: string; viewport?: string; content?: string; scrollbar?: string; thumb?: string }