Languages

CSS - how to change vertical scrollbar width?

8 points
Asked by:
Welsh
902

How can I change vertical scrollbar width?

More precisely, I want to change this part:

1 answer
2 points
Answered by:
Welsh
902

To change vertical scrollbar width you need to use custom styles for scrollbar, its track and thumb. In other case you won't be able to change the width.

Quick solution:

.container::-webkit-scrollbar {
    width: 12px;  /* <-------------------------- it changes vertical scrollbar width */
}

.container::-webkit-scrollbar-track {  /* <----- required                            */
    background: #efefef;
}

.container::-webkit-scrollbar-thumb {  /* <----- required                            */
    background: #ffea75;  
}

 

Practical example:

// ONLINE-RUNNER:browser;

<!DOCTYPE>
<html>
<head>
  <style>
    
    .container {
      	height: 100px;
      	width: 250px;
      	overflow-y: scroll;
    }
    
    .container::-webkit-scrollbar {
      	width: 12px;  /* <-------------------------- it changes vertical scrollbar width */
    }
    
    .container::-webkit-scrollbar-track {  /* <----- required                            */
        background: #efefef;
    }
    
    .container::-webkit-scrollbar-thumb {  /* <----- required                            */
        background: #ffea75;  
    }

  </style>
</head>
<body>
  <div class="container">
    Some text here...<br />Some text here...<br />Some text here...<br />
    Some text here...<br />Some text here...<br />Some text here...<br />
    Some text here...<br />Some text here...<br />Some text here...<br />
    Some text here...<br />Some text here...<br />Some text here...<br />
  </div>
</body>
</html>

 

See also

  1. CSS - style scrollbars (colors and size)

0 comments Add comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join