How to add arrows with -webkit-scrollbar-button
Asked Answered
H

5

31

I have a custom scrollbar. Since I did that, the arrows of the scrollbar are not shown anymore.

.scrollbar::-webkit-scrollbar-thumb {
    background-color: ##00a7e0;
  }

  .scrollbar::-webkit-scrollbar-track {
    background-color: #F5F5F5;
  }

  .scrollbar::-webkit-scrollbar-button {
    ????;
  }

What do I have to add in .scrollbar::-webkit-scrollbar-button that my arrows are shown again?

Hales answered 30/11, 2017 at 15:20 Comment(2)
Similar --> https://mcmap.net/q/454985/-adding-arrows-to-scrollbarHumoresque
@ovokuro I've seen this post too, but is it really the only solution? Can you only add the arrows by an image?Hales
L
36

(Super late to the party, but still)

You can style scrollbar buttons using ::-webkit-scrollbar-button selector (see this blog post for a full breakdown on the webkit scrollbar pseudo selectors), but getting them to show arrows is much trickier, and most people seem to either use background images or skip buttons altogether.

Here's a solution using CSS triangles for arrows:

https://mcmap.net/q/454986/-no-arrow-buttons-in-scrollbar-after-writing-webkit-css

and another one (based on the one above, vertical scrollbar only but the idea is the same):

::-webkit-scrollbar {
  width: 16px;
  border: 5px solid white;

}

::-webkit-scrollbar-thumb {
  background-color: #b0b0b0;
  background-clip: padding-box;
  border: 0.05em solid #eeeeee;
}

::-webkit-scrollbar-track {
  background-color: #bbbbbb;
}
/* Buttons */
::-webkit-scrollbar-button:single-button {
  background-color: #bbbbbb;
  display: block;
  border-style: solid;
  height: 13px;
  width: 16px;
}
/* Up */
::-webkit-scrollbar-button:single-button:vertical:decrement {
  border-width: 0 8px 8px 8px;
  border-color: transparent transparent #555555 transparent;
}

::-webkit-scrollbar-button:single-button:vertical:decrement:hover {
  border-color: transparent transparent #777777 transparent;
}
/* Down */
::-webkit-scrollbar-button:single-button:vertical:increment {
  border-width: 8px 8px 0 8px;
  border-color: #555555 transparent transparent transparent;
}

::-webkit-scrollbar-button:vertical:single-button:increment:hover {
  border-color: #777777 transparent transparent transparent;
}

(https://codepen.io/DarthVeyda/pen/eLLbXa)

Lamaism answered 17/9, 2018 at 5:40 Comment(1)
It looks like -webkit-scrollbar-button no longer works? I'm on a Mac and it's not showing at leastAggression
T
22

A newer version and better is this: How do I switch to Chromes dark scrollbar like GitHub does?


here is complete scrollbar with buttons with dark mode:

https://codepen.io/patrikx3/pen/ZEBQQyV

::-webkit-scrollbar {
    width: 16px;
    height: 16px;
}

::-webkit-scrollbar-corner,
::-webkit-scrollbar-track {
    background-color: rgb(64, 64, 64);
}

::-webkit-scrollbar-thumb {
    background-color: rgb(96, 96, 96);
    background-clip: padding-box;
    border: 2px solid transparent;
}

::-webkit-scrollbar-thumb:hover {
    background-color: rgb(112, 112, 112);
}

::-webkit-scrollbar-thumb:active {
    background-color: rgb(128, 128, 128);
}

/* Buttons */
::-webkit-scrollbar-button:single-button {
    background-color: rgb(64, 64, 64);

    display: block;
    background-size: 10px;
    background-repeat: no-repeat;
}

/* Up */
::-webkit-scrollbar-button:single-button:vertical:decrement {
    height: 12px;
    width: 16px;
    background-position: center 4px;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100' fill='rgb(96, 96, 96)'><polygon points='50,00 0,50 100,50'/></svg>");
}

::-webkit-scrollbar-button:single-button:vertical:decrement:hover {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100' fill='rgb(112, 112, 112)'><polygon points='50,00 0,50 100,50'/></svg>");
}

::-webkit-scrollbar-button:single-button:vertical:decrement:active {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100' fill='rgb(128, 128, 128)'><polygon points='50,00 0,50 100,50'/></svg>");
}

/* Down */
::-webkit-scrollbar-button:single-button:vertical:increment {
    height: 12px;
    width: 16px;
    background-position: center 2px;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100' fill='rgb(96, 96, 96)'><polygon points='0,0 100,0 50,50'/></svg>");
}

::-webkit-scrollbar-button:single-button:vertical:increment:hover {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100' fill='rgb(112, 112, 112)'><polygon points='0,0 100,0 50,50'/></svg>");
}

::-webkit-scrollbar-button:single-button:vertical:increment:active {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100' fill='rgb(128, 128, 128)'><polygon points='0,0 100,0 50,50'/></svg>");
}

/* Left */
::-webkit-scrollbar-button:single-button:horizontal:decrement {
    height: 12px;
    width: 12px;
    background-position: 3px 3px;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100' fill='rgb(96, 96, 96)'><polygon points='0,50 50,100 50,0'/></svg>");

}

::-webkit-scrollbar-button:single-button:horizontal:decrement:hover {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100' fill='rgb(112, 112, 112)'><polygon points='0,50 50,100 50,0'/></svg>");
}

::-webkit-scrollbar-button:single-button:horizontal:decrement:active {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100' fill='rgb(128, 128, 128)'><polygon points='0,50 50,100 50,0'/></svg>");
}

/* Right */
::-webkit-scrollbar-button:single-button:horizontal:increment {
    height: 12px;
    width: 12px;
    background-position: 3px 3px;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100' fill='rgb(96, 96, 96)'><polygon points='0,0 0,100 50,50'/></svg>");
}

::-webkit-scrollbar-button:single-button:horizontal:increment:hover {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100' fill='rgb(112, 112, 112)'><polygon points='0,0 0,100 50,50'/></svg>");
}

::-webkit-scrollbar-button:single-button:horizontal:increment:active {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100' fill='rgb(128, 128, 128)'><polygon points='0,0 0,100 50,50'/></svg>");
}
Toback answered 4/2, 2021 at 17:28 Comment(3)
A newer version an better is this: #65941022Toback
Your SVG coding on the scroller triangles helped me on this post.Sympathin
It looks like -webkit-scrollbar-button is no longer supported in Chrome? I'm on a Mac and it's not showing at leastAggression
L
6

Here's a light version.

::-webkit-scrollbar {
    width: 16px;
    height: 16px;
}

::-webkit-scrollbar-corner,
::-webkit-scrollbar-track {
    background-color:#eee;
}

::-webkit-scrollbar-thumb {
    background-color: #8f8e8e;
    background-clip: padding-box;
    border: 2px solid transparent;
}

::-webkit-scrollbar-thumb:hover {
    background-color: rgb(112, 112, 112);
}

::-webkit-scrollbar-thumb:active {
    background-color: rgb(128, 128, 128);
}

/* Buttons */
::-webkit-scrollbar-button:single-button {
    background-color: #eee;
    display: block;
    background-size: 10px;
    background-repeat: no-repeat;
}

/* Up */
::-webkit-scrollbar-button:single-button:vertical:decrement {
    height: 12px;
    width: 16px;
    background-position: center 4px;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100' fill='rgb(73, 73, 73)'><polygon points='50,00 0,50 100,50'/></svg>");
}

::-webkit-scrollbar-button:single-button:vertical:decrement:hover {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100' fill='rgb(112, 112, 112)'><polygon points='50,00 0,50 100,50'/></svg>");
}

::-webkit-scrollbar-button:single-button:vertical:decrement:active {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100' fill='rgb(128, 128, 128)'><polygon points='50,00 0,50 100,50'/></svg>");
}

/* Down */
::-webkit-scrollbar-button:single-button:vertical:increment {
    height: 12px;
    width: 16px;
    background-position: center 2px;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100' fill='rgb(73, 73, 73)'><polygon points='0,0 100,0 50,50'/></svg>");
}

::-webkit-scrollbar-button:single-button:vertical:increment:hover {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100' fill='rgb(112, 112, 112)'><polygon points='0,0 100,0 50,50'/></svg>");
}

::-webkit-scrollbar-button:single-button:vertical:increment:active {
    background-image
Lornalorne answered 22/3, 2021 at 19:45 Comment(2)
how about horizontal arrowsStempien
copy the vertical and just change it to horizontal.Lornalorne
S
3

Here's a more awesome design Codepen

Used Triangle SVG coverted to data URI

::-webkit-scrollbar-button:single-button:vertical:decrement {
  border-radius: 5px 5px 0 0;
  height: 16px;
  width: 16px;
  background-position: center 4px;
  background-image: url("data:image/svg+xml;utf8,<svg 
  xmlns='http://www.w3.org/2000/svg' width='100' height='100' fill='rgb(121, 
  255, 108)'><polygon points='50,00 0,50 100,50'/></svg>");
}
Skittish answered 3/8, 2021 at 16:55 Comment(0)
C
0

I was trying to add custom scroll arrows in macOS. Initially, I felt that ::-webkit-scrollbar-button was not working for Mac, but after some editing and fixing CSS, it seems to work for me (both Mac and Windows). Here is an example of the code:

  /* width */
 .scroll-d3-div::-webkit-scrollbar {
    height: 16px;
  };

  /* Track */
  .scroll-d3-div::-webkit-scrollbar-track:horizontal {
    background: #f1f1f1;
    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.1);
  };

  /* Handle */
  .scroll-d3-div::-webkit-scrollbar-thumb:horizontal {
    background: #C7C7C7;
    border-radius: 5px;
  }

  /* Handle on hover */
  .scroll-d3-div::-webkit-scrollbar-thumb:horizontal:hover {
    background: #888;
  }

  .scroll-d3-div::-webkit-scrollbar-button {
    display: block;
    background-color: #0099FE;
    background-repeat: no-repeat;
    background-size: 50%;
  }

  .scroll-d3-div::-webkit-scrollbar-button:horizontal:start:decrement {
    width: 22px;
    background-position: center;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100' fill='rgb(256, 256, 256)'><polygon points='0,50 50,100 50,0'/></svg>");
  }

  .scroll-d3-div::-webkit-scrollbar-button:horizontal:start:increment {
    display: none;
  }

  .scroll-d3-div::-webkit-scrollbar-button:horizontal:end:decrement {
    display: none;
  }

  .scroll-d3-div::-webkit-scrollbar-button:horizontal:end:increment {
    width: 22px;
    background-position:center right;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100' fill='rgb(256, 256, 256)'><polygon points='0,0 0,100 50,50'/></svg>");
  }

Here is how my horizontal scroll bar looks

Note: scroll-d3-div this class name is given to div with the overflow property.

You can also refer to the links below, which were helpful for me in driving this solution. https://www.webmound.com/create-custom-scrollbars-css-ultimate-guide/#:~:text=To%20style%20arrow%20buttons%20in,with%20%3Ahorizontal%20pseudo%2Dclass.

https://blog.shahednasser.com/how-to-style-a-scrollbar-with-css/#webkit-scrollbar-button

Coset answered 14/9, 2023 at 7:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.