CSS | ::-webkit-scrollbar

**::-webkit-scrollbar** là một pseudo-element trong CSS dùng để thay đổi giao diện scrollbar của trình duyệt. Trước khi bắt đầu, ta cần biết một số thông tin về element này.
  • Các trình duyệt như Chrome, Safari và Opera hỗ trợ tiêu chuẩn này.
  • Các trình duyệt như Firefox thì không hỗ trợ.
Với các trình duyệt webkit, bạn có thể dùng các pseudo-element sau để tùy chỉnh scrollbar:
  • ::-webkit-scrollbar: chính là scrollbar.
  • ::-webkit-scrollbar-button: các mũi tên lên xuống trên scrollbar.
  • ::-webkit-scrollbar-thumb: phần handle có thể kéo để cuộn trang.
  • ::-webkit-scrollbar-track: thanh tiến trình của scrollbar.
  • ::-webkit-scrollbar-track-piece: vùng không bị handle che khuất.
  • ::-webkit-scrollbar-corner: góc dưới của scrollbar nơi giao nhau.
  • ::-webkit-resizer: handle kéo để thay đổi kích thước ở góc dưới.
Ví dụ sau sẽ giải thích cách dùng của từng element (mỗi tag một màu khác nhau). HTML
<!Doctype>
<html>

<head>
    <title>scroll customization</title>
    <style type="text/css">
        body {
            font-size: 20pt;
        }
        /* tells the browser how the bar will look */
        
        ::-webkit-scrollbar {
            width: 15px;
            border: 2px solid blue;
        }
        /*tells the browser how the arrows will appear*/
        
        ::-webkit-scrollbar-button:single-button {
            background-color: red;
            height: 16px;
            width: 16px;
        }
        /* tells the browser how the scrollable 
          handle would look like */
        
        ::-webkit-scrollbar-thumb {
            background: black;
        }
        /* tells the browser how will the 
         path of the handle will look like */
        
        ::-webkit-scrollbar-track {
            background: yellow;
        }
        /* works the same as ::-webkit-scrollbar-track 
              but tells the browser how the path where 
              the handle is not present currently*/
        /* ::-webkit-scrollbar-track-piece{
            background: green;
        } */
        /* tells the browser how will the point 
           where vertical and  horizontal meet will look like*/
        /* ::-webkit-scrollbar-corner{
            background: orange ;
            display: solid;
        } */
        /* resizer*/
        
        ::-webkit-resizer {
            background: pink;
        }
    </style>
</head>

<body>
    <center>
        <h1 style="color:green">GeeksforGeeks</h1>
        <h2>CSS |::-webkit-scrollbar</h2>
        <p>HTML stands for Hyper Text Markup Language. 
          It is used to design web pages using markup language. 
          HTML is the combination of Hypertext and Markup language. 
          Hypertext defines the link between 
          the web pages. Markup language is used to 
          define the text document within tag which 
          defines the structure of web pages.</p>
        <br>
        <p>HTML is a markup language which is used by 
           the browser to manipulate text, images and 
          other content to display it in required format.</p>
        <br>
        <p>Cascading Style Sheets, fondly 
           referred to as CSS, is a simply
          designed language intended to simplify 
          the process of making web
          pages presentable. CSS allows you to 
           apply styles to web pages.
          More importantly, CSS enables you to 
          do this independent of the
          HTML that makes up each web page.</p>
    </center>
</body>

</html>
**Kết quả:**css-webkit-scrollbar **Trình duyệt hỗ trợ:** Các trình duyệt hỗ trợ **CSS | ::-webkit-scrollbar** được liệt kê dưới đây:
  • Google Chrome
  • Apple Safari
  • Opera

Last Updated : 21/07/2025