Style the scrollbar with css in Google Chrome (-webkit)

88,802

Solution 1

Here is an example that works:

::-webkit-scrollbar {
    height: 12px;
    width: 12px;
    background: #000;
}

::-webkit-scrollbar-thumb {
    background: #393812;
    -webkit-border-radius: 1ex;
    -webkit-box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.75);
}

::-webkit-scrollbar-corner {
    background: #000;
}

Or you can use jScrollPane.

Solution 2

.invisible-scrollbar {
  scrollbar-width: none;
}
.invisible-scrollbar::-webkit-scrollbar {
  display: none;
}

Solution 3

For anyone checking this answer after dec 2021, I added a snippet with @orel answer (updated the code, also added some html and changed the scrollbar style from background: #000; to background: #aaa; in order to spot the scroll better).

::-webkit-scrollbar {
    height: 12px;
    width: 12px;
    background: #aaa;
}

::-webkit-scrollbar-thumb {
    background: #393812;
    -webkit-border-radius: 1ex;
    -webkit-box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.75);
}

::-webkit-scrollbar-corner {
    background: #000;
}

.scrollable {
  max-width: 200px;
  max-height: 100%;
  
  height: 450px;
  /* change ` overflow: scroll ` to ` overflow: auto ` if you only want vertical scroll */
  overflow: scroll;
 }
<div class="scrollable">
What is Lorem Ipsum?
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Why do we use it?
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
</div>
Share:
88,802
Alexandru Vlas
Author by

Alexandru Vlas

Updated on January 30, 2022

Comments

  • Alexandru Vlas
    Alexandru Vlas over 2 years

    Can somebody please help me? I want to do a simple style for the scrollbar. I found some information on the internet and tried it, but it seems that it doesn't really work for some reasons. The scrollbar looks fine when refreshing the page, but as soon as you touch the scrollbar it goes crazy. It fills with a lot of colours and you can't understand that that is a scrollbar.

    Here how it looks before you touch it - http://i40.tinypic.com/a2evro.png

    Here how it looks after you touch it - http://i44.tinypic.com/qzkirn.png

    Here is the code that I put in css:

    ::-webkit-scrollbar {
    width: 16px;
    height: 16px; }
    
    ::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.2);
    -webkit-box-shadow: inset 1px 1px 0 rgba(0,0,0,0.10),inset 0 -1px 0 rgba(0,0,0,0.07); }
    

    Thank you all. Cheers. Alex

  • Vinay Kaithwas
    Vinay Kaithwas over 2 years
    Both link broken
  • Huy - Logarit
    Huy - Logarit about 2 years
    doesn't work on chrome mobile iphone xsmax
  • Berci
    Berci about 2 years
    According to caniuse.com/css-scrollbar after iOS 14 (including 15.4) CSS scrollbar styling is not supported for some reason (neither on safari or on Chrome)