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.
<style> /* width */ ::-webkit-scrollbar { width: 18px; } /* Track */ ::-webkit-scrollbar-track { background: #f1f120; } /* Handle */ ::-webkit-scrollbar-thumb { background: #881; } </style>
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;
/* Handle on hover */ ::-webkit-scrollbar-thumb:hover { background: #520; }
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:
/* Custom Button */ ::-webkit-scrollbar-button:single-button { background-color:none; display: block; border-style: solid; height: 13px; width: 16px; }
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:
<style> /* Custom width for the Scrollbar */ ::-webkit-scrollbar { width: 18px; } /* Custom Track */ ::-webkit-scrollbar-track { box-shadow: inset 0 0 5px grey; border-radius: 10px; background: #f1f120; } /* Handle */ ::-webkit-scrollbar-thumb { background: #881; border-radius: 10px; } /* Handle on hover */ ::-webkit-scrollbar-thumb:hover { background: #520; } /* Custom Button */ ::-webkit-scrollbar-button:single-button { background-color:none; display: block; border-style: solid; height: 13px; width: 16px; } /* Custom Up Direction Button */ ::-webkit-scrollbar-button:single-button:vertical:decrement { border-width: 0px 8px 9px 8px; border-color: transparent #881; border-radius: 10px; } /* Custom Down Direction Button */ ::-webkit-scrollbar-button:single-button:vertical:increment { border-width: 0px 8px 9px 8px; border-color: transparent #881; border-radius: 10px; } </style>
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.
<link rel="stylesheet" href="https://unpkg.com/simplebar@latest/dist/simplebar.css"> <strong> </strong><script src="https://unpkg.com/simplebar@latest/dist/simplebar.js"></script>
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

<style> :root { --primary: #212123; } body, html{ height: 100vh; } body{ background: var(--primary); font-family:Georgia, "Times New Roman", Times, serif; color: #fff; display:grid; grid-columns:60% auto; margin: 0; } p{ margin: 1em; padding: 1em; background-color: #333; border-radius:10px; color: #99F; } h2 { color: #996; } .simplebar-scrollbar:before{background-color:#0F0; } .simplebar-scrollbar{margin-right:3px; } </style>
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!

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

The role of HTML is to define the structure and content of a web page through tags and attributes. 1. HTML organizes content through tags such as , making it easy to read and understand. 2. Use semantic tags such as, etc. to enhance accessibility and SEO. 3. Optimizing HTML code can improve web page loading speed and user experience.

HTMLisaspecifictypeofcodefocusedonstructuringwebcontent,while"code"broadlyincludeslanguageslikeJavaScriptandPythonforfunctionality.1)HTMLdefineswebpagestructureusingtags.2)"Code"encompassesawiderrangeoflanguagesforlogicandinteract

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Zend Studio 13.0.1
Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download
The most popular open source editor