CSS scrollbars styling

فهرست فصل‌ها دانلود آرشیوناشر

MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونه‌کد

The CSS scrollbars styling module defines properties that you can use for visual styling of scrollbars. You can customize the scrollbar width as needed. You can also customize the scrollbar _track_ color (the background) and the scrollbar _thumb_ color (the draggable handle).

Scrollbar styling in action

This example defines a thin scrollbar with a teal thumb and lighter teal track. To see the thumb, scroll the text. After the scrollbar is visible, hover over it to see the track.

css hidden
css
.poem {
  overflow: scroll;
  scrollbar-color: #0b4f4a #5f9e98;
  scrollbar-width: thin;
}
html hidden

{{EmbedLiveSample("Scrollbar_styling_in_action")}}

توجه: When customizing scrollbars, ensure that the thumb and track have enough contrast with the surrounding background. Also ensure that the scrollbar hit area is large enough for people who use touch input.

Reference

CSS properties

  • {{CSSxRef("scrollbar-width")}}
  • {{CSSxRef("scrollbar-color")}}

Related concepts

  • {{CSSxRef("overflow-block")}} CSS property
  • {{CSSxRef("overflow-inline")}} CSS property
  • {{CSSxRef("overflow-x")}} CSS property
  • {{CSSxRef("overflow-y")}} CSS property
  • {{CSSxRef("overflow")}} CSS shorthand property
  • {{CSSxRef("overflow-clip-margin")}} CSS property
  • {{CSSxRef("scrollbar-gutter")}} CSS property
  • {{CSSxRef("scroll-behavior")}} CSS property
  • {{cssxref("scroll-margin")}} CSS shorthand property
  • {{cssxref("scroll-padding")}} CSS shorthand property
  • {{cssxref("scroll-snap-align")}} CSS property
  • {{cssxref("scroll-snap-stop")}} CSS property
  • {{cssxref("scroll-snap-type")}} CSS property
  • {{CSSxRef("::-webkit-scrollbar")}} pseudo-element
  • {{glossary("scroll container")}} glossary term
  • [scrollbar](/en-US/docs/Web/Accessibility/ARIA/Reference/Roles/scrollbar_role) ARIA role

Specifications

{{Specifications}}

See also

  • {{cssxref('scroll-timeline')}}, {{cssxref('scroll-timeline-axis')}}, {{cssxref('scroll-timeline-name')}}
  • CSS overflow module
  • CSS scroll snap module