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 Structuremodule.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 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.HTML<html> <head> <style>
2 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 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 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. To
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 Control The Scroll Snap in Tailwind CSS? To simplify scroll snap effects, a utility-first CSS framework, Tailwind CSS, helps with some utilities. When scroll snapping is in place, users are guided through the content smoothly by snapping elements into position as they scroll down the page, resulting in a more polished and responsive experi
4 min read
How to Create a Custom Scrollbar using CSS? Scrollbars are common graphical user interface elements that allow users to navigate content beyond the visible area. By default, web browsers provide basic scrollbars with a predefined style. However, using HTML and CSS, you can customize the scrollbar to match your website's design better.Scrollba
4 min read
How to Code Pixel Perfect Design using Tailwind CSS ? Pixel-perfect design refers to the ability to create designs that are accurate down to the pixel level. Tailwind CSS is a popular utility-first CSS framework that can help developers to create pixel-perfect designs quickly and efficiently. In this article, we'll discuss how to code pixel-perfect des
5 min read
How to style HTML Tables with Tailwind CSS ? TailwindCSS offers utilities to make tables visually appealing. The colored header table emphasizes visual hierarchy through background color, while the stripped row table improves readability with alternating row colors. Similarly, the hover effect table enhances user interaction by applying visual
5 min read
How to Install Tailwind CSS with Create React App? We will see how to set up Tailwind CSS in a React project using the Create React App. Tailwind CSS is a utility-first CSS framework that allows for rapid development of custom user interfaces. When combined with Create React App, it offers a flexible approach to build modern React applications.Prere
2 min read