How to create a custom scrollbar with CSS?

CSSWeb DevelopmentFront End Technology

To create a custom scrollbar with CSS, the code is as follows −

Example

 Live Demo

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
   body {
      font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
      height: 200vh; /*to create a scrollbar*/
   }
   ::-webkit-scrollbar {
      width: 20px;
   }
   p {
      font-size: 40px;
   }
   ::-webkit-scrollbar-track {
      box-shadow: inset 0 0 5px grey;
      border-radius: 10px;
   }
   ::-webkit-scrollbar-thumb {
      background: rgb(75, 22, 161);
      border-radius: 2px;
   }
   ::-webkit-scrollbar-thumb:hover {
      background: #9156ff;
   }
</style>
</head>
<body>
<h1>Custom Scrollbar Example</h1>
<h2>Will not work in IE,Edge and Firefox</h2>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Dolore, rerum. Placeat molestias 
quisquam doloremque, perferendis aspernatur quod cupiditate cumque porro cum facilis vel 
dolorem fuga dolore quae deserunt sint inventore distinctio et, modi sunt! Commodi omnis 
adipisci autem enim, perferendis, modi possimus quos, ducimus error hic natus voluptate. 
Error, rem!
</p>
</body>
</html>

Output

The above code will produce the following output −

raja
Published on 08-May-2020 14:26:32
Advertisements