@gradin/tailwindcss-scrollbar

中文文档
3.0.1发布于 2022/11/17MITCommonJS零依赖近 30 天下载 4.2万

Tailwindcss plugin to customize scrollbar.

原始使用文档
文档目录6 节
  1. Installation
  2. Configuration
  3. Multiple scrollbar styles
  4. Dark Mode
  5. Hides scrollbar.
  6. Browser Support

tailwindcss-scrollbar

Tailwindcss plugin to customize browser scrollbar.

npm (scoped) npm bundle size (scoped) npm

Live Demo

Installation

# Using npm
npm install -D @gradin/tailwindcss-scrollbar

# Using Yarn
yarn add -D @gradin/tailwindcss-scrollbar

Then add the plugin to tailwind.config.js file.

module.exports = {
  theme: {
    // ...
  },
  plugins: [
    require('@gradin/tailwindcss-scrollbar'),
  ],
}

Configuration

You can customize the size and color of the scrollbar. Also supports any css attributes such as borderRadius.

⚠️ See release notes if you are upgrading from v1 ⚠️

module.exports = {
  theme: {
    // ...
  },
  plugins: [
    require('@gradin/tailwindcss-scrollbar')({
      size: '5px', // width or height, default '5px'
      track: {
        background: 'lightgray', // default '#f1f1f1'
        // add other css attributes here,
        // will be merged to ::-webkit-scrollbar-track
      },
      thumb: {
        background: 'gray', // default '#c1c1c1'
        borderRadius: '40px',
        // add other css attributes here,
        // will be merged to ::-webkit-scrollbar-thumb
      },
      hover: {
        background: 'darkgray', // default '#a8a8a8'
        borderRadius: '40px',
        // add other css attributes here,
        // will be merged to ::-webkit-scrollbar-thumb:hover
      },
    }),
  ],
}

To use attributes from your config.theme, you need to override theme.scrollbar.DEFAULT.

module.exports = {
  theme: {
    // ...
    scrollbar: theme => ({
      DEFAULT: {
        size: theme('spacing.1'),
        track: {
          background: theme('colors.gray.300'),
        },
        thumb: {
          background: theme('colors.gray.400'),
        },
        hover: {
          background: theme('colors.gray.500'),
        },
      },
    })
  },
  plugins: [
    require('@gradin/tailwindcss-scrollbar'),
  ],
}

Multiple scrollbar styles

You can add more scrollbar styles using theme.scrollbar.STYLE_NAME

They need to have size, track, thumb, hover property specified, as they don't have default value.

module.exports = {
  theme: {
    // ...
    scrollbar: {
      thin: {
        size: '2px',
        track: { background: 'lightgray' },
        thumb: { background: 'gray' },
        hover: { background: 'darkgray' },
      },
      blue: {
        size: '8px',
        track: { background: 'lightblue' },
        thumb: { background: 'blue' },
        hover: { background: 'darkblue' },
      },
    },
  },
}
<div class="overflow-auto scrollbar-thin"></div>
<div class="overflow-auto scrollbar-blue"></div>

Dark Mode

To set different background color on dark mode, you can use darkBackground attribute. If unset, they will have the same color as the background.

track: {
  background: theme('colors.gray.300'),
  darkBackground: theme('colors.gray.800'),
},
thumb: {
  background: theme('colors.gray.400'),
  darkBackground: theme('colors.gray.600'),
},
hover: {
  background: theme('colors.gray.500'),
  darkBackground: theme('colors.gray.500'),
},

Hides scrollbar.

To hide the scrollbar but still make it scrollable, use scrollbar-none class on the element with overflow: auto | scroll.

<div class="overflow-auto scrollbar-none">
  <!-- Very long content here -->
</div>

This is done by using scrollbar-width: none on Firefox and ::-webkit-scrollbar{display:none} on Chrome.

Browser Support

This plugin uses ::-webkit-scrollbar to modify scrollbar style.

Not supported in all versions of Firefox and Edge version 78 or older.

See Browser Compatibility

.scrollbar-none is supported on Firefox version 64 or newer.

版本与发布记录

@gradin/tailwindcss-scrollbar 共发布 20 个版本,首次发布于 2021/04/10;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.0.1latest2022/11/173 年前
3.0.02022/11/164 年前
2.1.1-beta.7next2022/11/164 年前
2.1.1-beta.62022/11/164 年前
2.1.1-beta.52022/11/164 年前
2.1.1-beta.42022/11/164 年前

关于 @gradin/tailwindcss-scrollbar 的常见问题

@gradin/tailwindcss-scrollbar 是什么?

Tailwindcss plugin to customize scrollbar.

如何安装 @gradin/tailwindcss-scrollbar?

在项目目录运行 npm install @gradin/tailwindcss-scrollbar,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:tailwindcss(>=2.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@gradin/tailwindcss-scrollbar 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/gradin__tailwindcss-scrollbar 是否存在。

@gradin/tailwindcss-scrollbar 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@gradin/tailwindcss-scrollbar 可以商用吗?

@gradin/tailwindcss-scrollbar 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@gradin/tailwindcss-scrollbar 的下载量有多少?

根据 npm 官方下载统计,@gradin/tailwindcss-scrollbar 在 2026/10/17 – 2026/11/15 这 30 天内被下载 42,355 次,日均约 1,412 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@gradin/tailwindcss-scrollbar 还在维护吗?

最新版本 3.0.1 发布于 2022/11/17(3 年前);至今共发布 20 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/04/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。