How to Change Style of Scrollbar using Tailwind CSS?
Last Updated :
26 Apr, 2025
By default, Tailwind CSS does not include built-in utilities for styling scrollbars. However, you can customize the appearance of scrollbars using traditional CSS in combination with Tailwind’s utility classes. This is achieved by using the scrollbar-* classes to customize aspects like scrollbar width, color, and behavior.
To style the scrollbar, you’ll use WebKit-based pseudo-elements like ::-webkit-scrollbar, which are supported by browsers such as Chrome and Safari. These pseudo-elements allow you to control various parts of the scrollbar, such as its track and thumb.
::-webkit-scrollbar {
/* Customize the scrollbar width */
}
::-webkit-scrollbar-track {
/* Customize the scrollbar track */
}
::-webkit-scrollbar-thumb {
/* Customize the scrollbar thumb */
}
- ::-webkit-scrollbar: Targets the entire scrollbar, allowing you to set its width/height.
- ::-webkit-scrollbar-track: Styles the track (background) where the thumb moves.
- ::-webkit-scrollbar-thumb: Styles the thumb (draggable part) of the scrollbar.
Note: It works for WebKit browsers like Chrome, Safari, etc.
Let’s walk through the process of setting up a Next.js project with Tailwind CSS, and applying custom scrollbar styles.
Step 1: Create a new Next Project
You can create a new Next application using the command below.
npx create-next-app scrollbar
Step 2: Install Tailwind
Once your next project is created, open the project’s root directory and install the tailwind dependencies with the following command.
npm install -D tailwindcss postcss autoprefixer
Step 3: Create Tailwind config file
Run the following command to create a tailwind config file, this file can be used to extend the tailwind’s functionality.
npx tailwindcss init -p
Project Structure

Next.js Project Structure
module.exports = {
content: [
"./pages/**/*.{js,ts,jsx,tsx}",
"./components/**/*.{js,ts,jsx,tsx}",
],
theme: {
extend: {},
},
plugins: [],
};
Step 5: Add Tailwind directives
In your /styles/global.css file, add the layer directives of tailwind CSS.
@tailwind base;
@tailwind components;
@tailwind utilities;
Example 1: In this example, we’ll add the scrollbar styles to our global CSS file.
CSS
/* global.css */
@tailwind base;
@tailwind components;
@tailwind utilities;
/* width */
::-webkit-scrollbar {
width: 10px;
}
/* Track */
::-webkit-scrollbar-track {
background: #f1f1f1;
}
/* Handle */
::-webkit-scrollbar-thumb {
background: #888;
border-radius: 5px;
}
/* Handle on hover */
::-webkit-scrollbar-thumb:hover {
background: #555;
}
JavaScript
// pages/index.js
export default function Home() {
return (
<div className="min-h-[200vw]">
<img className="fixed top-1/2 left-1/4 w-96"
src=
"https://media.geeksforgeeks.org/wp-content/cdn-uploads/logo-new-2.svg"
alt="" />
</div>
)
}
Steps to Run: Use this command in the project directory to run the application
npm run dev
Output

Change the scrollbar when using Tailwind (next.js/react)
Example 2: Further, if you want a scrollbar for the dark theme you can customize it as shown in global.css file
CSS
/* global.css*/
@tailwind base;
@tailwind components;
@tailwind utilities;
/* width */
::-webkit-scrollbar {
width: 10px;
}
/* Track */
::-webkit-scrollbar-track {
background: #888;
border-radius: 5px;
}
/* Handle */
::-webkit-scrollbar-thumb {
background: #000;
border-radius: 5px;
}
/* Handle on hover */
::-webkit-scrollbar-thumb:hover {
background: #555;
}
JavaScript
// pages.index.js
export default function Home() {
return (
<div className="min-h-[200vw]">
<img className="fixed top-1/2 left-1/4 w-96"
src=
"https://media.geeksforgeeks.org/wp-content/cdn-uploads/logo-new-2.svg"
alt="" />
</div>
)
}
Output

How to change scrollbar when using Tailwind (next.js/react)
Conclusion
While Tailwind CSS does not have built-in utilities for customizing scrollbars, you can easily achieve this by using WebKit-based pseudo-elements like ::-webkit-scrollbar, ::-webkit-scrollbar-track, and ::-webkit-scrollbar-thumb. By integrating these custom CSS styles with Tailwind, you can create a fully responsive and visually appealing scrollbar that fits your project’s design.
Similar Reads
How to Change Style of Scrollbar using Tailwind CSS ?
By default, Tailwind CSS does not include built-in utilities for styling scrollbars. However, you can customize the appearance of scrollbars using traditional CSS in combination with Tailwind's utility classes. This is achieved by using the scrollbar-* classes to customize aspects like scrollbar wid
3 min read
How to Change the Position of Scrollbar using CSS?
Here are the Methods to Change the Position of the Scrollbar using CSS: Method 1. Using the direction PropertyThe direction property specifies the text direction of an element's content. Setting it to rtl (right-to-left) moves the scrollbar to the left side. [GFGTABS] HTML <html> <head>
3 min read
How to Create A Sticky NavBar Using Tailwind CSS?
Sticky Navbar in Tailwind CSS is mostly used in applications where maintaining quick access to navigation links is essential as users scroll through content. It ensures that the navbar remains visible at the top of the screen, enhancing user experience by providing constant access to key sections of
4 min read
How to style a href links in React using Tailwind CSS ?
In this article, we will learn how we can style a href link in Reactjs. Since we use Tailwind CSS, Tailwind CSS describes itself as the first applicable CSS framework. Rather than focusing on the performance of a style object, Tailwind focuses on how it should be displayed. This makes it easier for
2 min read
How to Implement Smooth Scrolling using Tailwind CSS ?
Smooth scrolling refers to the scrolling of a section of the webpage when the respective link is clicked. By default when we click a link it skips directly to that element using smooth scrolling the UX improves a lot. Tailwind CSS provides a utility class named scroll-smooth which applies the CSS pr
2 min read
How to change style of elements on scroll using jQuery ?
We have given an HTML document containing some CSS properties, and the task is to change the CSS property to a particular element after scrolling the page using jQuery. To change the style of element on scroll, we get the number of pixels by which the content of an element has been scrolled horizont
2 min read
How to change the width on hover using Tailwind CSS ?
In this article, we will change the width on hover using Tailwind. There is no inbuilt method in Tailwind, so you have to customize the tailwind.config.js file. Let's discuss the whole process further in this article. By default, tailwind CSS only generates responsive variants for width utilities. T
3 min read
How to Create Multiple Themes using Tailwind CSS ?
In this article, we will discuss how to create multiple themes using Tailwind CSS. Tailwind CSS is a popular utility-first CSS framework that provides a lot of pre-designed CSS classes for designing websites. With Tailwind CSS, you can easily create multiple themes for your website. This means that
3 min read
How to apply Dynamic Styles using Tailwind CSS?
Tailwind CSS helps you style your website easily by using simple classes. Sometimes, you might need to change these styles based on different conditions, like when a button is clicked. Below are the approaches to apply dynamic styles using Tailwind CSS: Table of Content Using Inline StylesUsing CSS
3 min read
How to Style Checkboxes in Tailwind CSS ?
In Tailwind CSS, you can style checkboxes using utility classes to customize their appearance. You can use utility classes like appearance-none to remove the default browser styles from checkboxes. ApproachBegin with the basic HTML structure, including the <!DOCTYPE html> declaration, <html
3 min read