Setting the scroll bar finger icon using CSS

Using CSS to Set the Scroll Bar Finger Symbol

Using CSS to Set the Scroll Bar Finger Symbol

In web development, we often use scroll bars to scroll and view content. However, on mobile devices, the user experience may be affected because the default scroll bar doesn’t conform to touch-sensitive scrolling habits. To improve the user experience, we can use CSS to customize the scroll bar and add finger icons to make it more user-friendly.

Why Customize Scroll Bar Finger Icons?

Currently, mobile devices are increasingly used for web browsing. However, touch-sensitive scrolling on mobile devices differs from traditional mouse scrolling. On mobile devices, the default scroll bar doesn’t conform to user touch-sensitive scrolling habits, resulting in a poor user experience.


To improve the user experience, we can customize the scrollbar and add finger icons to simulate the swipe gestures on mobile devices, allowing users to browse web content more conveniently and quickly.

How to Set the Scrollbar Finger Icon Using CSS

To implement a custom scrollbar finger icon, we need to use some specific CSS properties to style the scrollbar. Here are some common CSS properties for customizing scrollbars:

  • ::-webkit-scrollbar: Used to set the scrollbar style for WebKit-based browsers.
  • ::-webkit-scrollbar-thumb: Used to set the scrollbar thumb style.
  • ::-webkit-scrollbar-track: Used to set the scrollbar track style.
  • ::-webkit-scrollbar-button: Used to set the scrollbar button style.

Next, we’ll use example code to demonstrate how to use CSS to set the scrollbar thumb icon.

/* Set scrollbar width and color */
::-webkit-scrollbar {
width: 10px;
background-color: #ccc;
}

/* Set thumb style */
::-webkit-scrollbar-thumb {
background-color: #666;
border-radius: 10px;
}

/* Set track style */
::-webkit-scrollbar-track {
background-color: #eee;
}

/* Set finger icon style */
::-webkit-scrollbar-thumb:active {
background-color: #999; 
}

In the sample code above, we use ::-webkit-scrollbar, ::-webkit-scrollbar-thumb, and ::-webkit-scrollbar-track to set the scrollbar’s width, color, thumb style, and track style, respectively. We also use ::-webkit-scrollbar-thumb:active to set the style of the thumb when it’s clicked, simulating finger movement.

Sample Code Run Results

The following is a simple HTML sample code that demonstrates how to use CSS to set the scroll bar finger mark effect:

<!DOCTYPE html> 
<html Tutorial">html lang="en"> 
<head> 
<meta charset="UTF-8"> 
<meta name="viewport" content="width=device-width, initial-scale=1.0"> 
<title>CSS Scrollbar Finger Symbol Example</title> 
<style> 
/* Set scrollbar width and color */ 
::-webkit-scrollbar { 
width: 10px; 
background-color: #ccc; 
} 

/* Set thumb style */ 
::-webkit-scrollbar-thumb { 
background-color: #666; 
border-radius: 10px; 
} 

/* Set track style */ 
::-webkit-scrollbar-track { 
background-color: #eee; 
} 

/* Set finger symbol style */ 
::-webkit-scrollbar-thumb:active { 
background-color: #999; 
} 

/* Set content area height and overflow properties */ 
.content { 
height: 200px; 
overflow-y: scroll; 
} 
</style> 
</head> 
<body> 
<div class="content"> 
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eget ante dolor. Integer at varius eros. Maecenas fermentum, purus vel congue bibendum, metus lacus consequat magna, ut porta enim purus vel nunc.</p> 
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nam euismod elit at justo aliquam, id varius libero congue. Vivamus nec feugiat mi.</p> 
<p>Quisque a mi sit amet lorem rutrum iaculis. Ut quis purus eget nulla bibendum aliquet nec eget erat. Pellentesque eget dolor nec turpis congue mattis.</p> 
<p>Suspendisse semper fermentum venenatis. Phasellus eleifend vel leo a dapibus. Cras vel eleifend metus. 
</div> 
</body> 
</html> 

In the above sample code, we have achieved the effect of customizing the scroll bar finger mark by setting CSS properties such as ::-webkit-scrollbar. Users can easily browse the content through the scroll bar, and when the slider is clicked, a finger mark effect will be displayed.

In short, by using CSS to set the scroll bar finger symbol, we can improve the user’s browsing experience on mobile devices and make it more convenient and quick for users to view web content.

Leave a Reply

Your email address will not be published. Required fields are marked *