Scrollbar Color
A scroll bar is a movable bar, generally located at the very right or at the bottom of your screen. A scroll bar is either horizontally mounted or vertically, allowing the user to move the window up and down or right and left. In other words, the scroll bar is a widget or a technique that creates an interaction between the user and the system window display, which scrolls a continuous picture or a text or any kind of display. The scroll bar contains a ‘BAR’ or commonly known as ‘TRACK’, and this bar has a ‘THUMB’ that is used to move the window contents, up and down or right and left. In this topic, we are going to learn about Scrollbar Color.
Generally, the scroll bar you find is usually block-shaped and gray in color. But the default color and other properties of the scroll bars can be manipulated and customized using CSS or JavaScript, or both.
In the coming sections, we will try and create scroll bars manipulated using CSS and Javascript.
Customization of Scrollbar Color
The color property simply helps to set a different color, other than default gray for the ‘thumb’ and the usual track color. We all know that the background area color for the scroll bar ( which is generally fixed no matter in which direction the user scrolls ) is known as the ‘TRACK’. And the moving part, which actually scrolls along with the scrolling window, it floats on the track, is called the ‘THUMB’.
Below is a visual example figure explaining the track and the thumb.
The above image is a simple representation of a web page with overflowed information. The user has to click on the thumb and drag it in the up and down direction to view the complete information.
The Scroll Bar that can be seen in the above image is a Default Browser-based Scroll Bar with its default values. We keep talking about default values; let’s see them as well.
-
: Defines the color of your scroll bar and the default values it carries as below: - auto: ‘auto’ is the default property for the track of the scroll bar if the programmer has not given any specific color or property.
- dark: ‘dark’ property, when provided, shows a dark scroll bar that can be one of the darker shades of the color provided by your browser or platform or the darker shade of the color defined by you.
- light: ‘light’ property shows the lighter shade of the platform provided color or the color you set for the scroll bar.
-
: The first color signifies the color for the scroll bar’s thumb, and the second color represents the color for the track.
The
The browsers such as Opera, Chrome, Safari are -webkit- browsers and thus support the non-standard pseudo-element called, “:: -webkit-scrollbar” element, which allows us to make changes to our scroll bar easily irrespective of the browsers.
The properties are set to ‘auto’ by default, which, when manipulated, can create the visuals really interesting. These elements are added at the top of your code (see below) in the section to customize the browser’s default scroll bar properties.
Examples of Scrollbar Color
We created the following example of a simple scroll bar with a width of 18 pixels. We gave it a yellow tack color with a leafy green bar or handle color.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
One more property can be added to the bar or handle, ‘::-webkit-scrollbar-thumb:hover’, which helps you set a different color to your scroll bar when it has hovered over.
To add a ‘hover over’ property to our bar or handle, we just need to add the following code lines to our script;
1 2 3 4 |
|
And the result can be seen in the below screenshot:
Our leafy-green colored bar changed to Brown when hovered over.
Let’s see another example of exploring more properties. In the following example, we smoothed out our bar and the thumb using the border radius property. The interesting thing is to create buttons for users to easily move the bar on the track by clicking on the buttons instead of dragging the bar.
We have added the below code for creating our own custom button:
1 2 3 4 5 6 7 8 |
|
The above will simply display the area with a border where our buttons will appear, as shown below. This will need some customization as well.
After our customization (see the code added) is done, we get the final result. See the results for yourselves:
Complete code is given below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
SimpleBar: A JavaScript Library
There is always another way to implement elements in your project. A custom scroll bar can also be added with the help of jquery plugins and javascript libraries, popular in the web market. For example, SimpleBar is the new Javascript library that makes it easier for the author to create customized scrollbars.
It’s a standalone library that adds a scroll bar to any scrollable element or component, or container which might have overflowing content. This javascript library makes your content dynamic and keeps the native scroll behavior. A simple demo is shown below.
Customization
You can easily use these javascript libraries by installing and importing them into your projects or directly including them and their CSS files (if any) on to your HTML page. In the below example, we will be using the second option, directly including a javascript library into our program.
1 2 |
|
Adding these two lines to your HTML page will include and attach a remote file that can not be edited to your HTML like this; Next, we will add, ‘data-simplebar’ attribute to the division or the content, which will be the scrollable container of your HTML page. In our example, we added this attribute to the tag itself. Along with this, we will require a sample text; I have added ‘Lorem Ipsum’ default text to our tag to make the web page scrollable. And that is it. Simple right? When this is all done, your web page will look like this –>
But it’s still raw and a bit ugly. I have done a few tweaks, as shown below, and see the results for your selves. The full code for CSS is given below, along with the results.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
And the result is, as you can see below;
You can manually configure the javascript libraries as well, but then you need to initialize them first and then configure them; an option is known as ‘override’ is used, passing the object as a parameter of our Simplebar Function.
You can design it as you want since this library is lightweight. It has a simplebar.js file, a vanilla javascript custom scroll bar plugin that ensures great performance and works with all browsers.
The above is the detailed content of Scrollbar Color. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an
