How To Create Custom Scrollbar in CSS


A world where the seemingly small details can make a huge impact on your website’s aesthetic and user experience. In this intriguing tutorial, we’re diving into the art of customizing your website’s scrollbar using only HTML and CSS—that’s right, no JavaScript required!

You have the freedom to design a scrollbar that aligns perfectly with your website’s theme, creating a seamless and immersive user experience.

But how can this be achieved without delving into the complexities of JavaScript? That’s the beauty of this tutorial; it’s crafted for both novices and seasoned web developers, ensuring that anyone can transform their website’s scrollbar into a stunning visual element.

We’re not just talking about a simple color change. This guide will take you through the intricacies of styling—from adjusting widths to perfecting the scrollbar’s feel and responsiveness.

The scrollbar, often overlooked, can be a powerful tool in enhancing the overall look and feel of your site.

Essential Files for Scrollbar Customization

To begin, you’ll need two key files: index.html and style.css. We’ll start by embedding some fundamental HTML code into the index.html file. It’s important to establish a connection between your HTML and CSS files. This is achieved by linking the style.css file to the index.html page using the <link> tag.

body {
    margin: 40px;
    line-height: 24px;

p {
    text-align: justify;

::-webkit-scrollbar {
    background: #95a5a6;
    width: 14px;

::-webkit-scrollbar-thumb {
    background: #2c3e50;

Customizing Without JavaScript

Let’s delve into the CSS aspect. We’ll be focusing on the body and paragraph elements initially. The body element will be styled with a margin of 40 pixels and a line-height of 24 pixels, ensuring a clean and readable layout.

For the paragraph (p) element, we’ll set the text alignment to justify, creating a polished and professional appearance.

The most exciting part of this tutorial is customizing the scrollbar. To do this, we’ll utilize the ::-webkit-scrollbar and ::-webkit-scrollbar-thumb pseudo-elements in CSS. These elements allow us to modify the look of the scrollbar, providing a seamless integration with your site’s design.

In our example, the ::-webkit-scrollbar is given a background color of #95a5a6 and a width of 14 pixels, ensuring it’s visibly distinct yet not overpowering.

The ::-webkit-scrollbar-thumb, which is the draggable part of the scrollbar, is styled with a background color of #2c3e50, creating a contrast that enhances user interaction.


In conclusion, the journey through customizing your website’s scrollbar using HTML and CSS demonstrates that even the smallest elements can have a significant impact on your site’s overall appeal and functionality.

This tutorial has shown that with some creativity and a good understanding of CSS, you can transform a basic, functional element into a powerful design tool that enhances user experience.

Remember, in the world of web design, every detail counts, and the scrollbar is no exception. Embrace the opportunity to make your website not just functional, but visually engaging and memorable for your users.