Open In App

How to Change the Position of Scrollbar using CSS?

Last Updated : 11 Jan, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Here are the Methods to Change the Position of the Scrollbar using CSS:

Method 1. Using the direction Property

The direction property specifies the text direction of an element’s content. Setting it to rtl (right-to-left) moves the scrollbar to the left side.

HTML
<html>
<head>
    <style>
        .scroll-left {
            direction: rtl;
            overflow-y: scroll;
            height: 150px;
            width: 300px;
            border: 1px solid #000;
        }
        .content {
            direction: ltr;
        }
    </style>
</head>
<body>
    <div class="scroll-left">
        <div class="content">
            This is a sample Code 
        </div>
    </div>
</body>
</html>
  • The .scroll-left class applies direction: rtl; to move the scrollbar to the left.
  • The inner .content div resets the text direction to left-to-right with direction: ltr;.

2. Using the transform Property

The transform property can rotate elements, effectively repositioning the scrollbar.

HTML
<html>
<head>
    <style>
        .scroll-left {
            transform: rotateY(180deg);
            overflow-y: scroll;
            height: 150px;
            width: 300px;
            border: 1px solid #000;
        }
        .content {
            transform: rotateY(180deg);
        }
    </style>
</head>
<body>
    <div class="scroll-left">
        <div class="content">
            This is sample code 
        </div>
    </div>
</body>
</html>
  • The .scroll-left class applies transform: rotateY(180deg); to flip the container, moving the scrollbar to the left.
  • The inner .content div reverses the flip to display content normally.

3. Using overflow-x and transform for Top Scrollbar

To position the scrollbar at the top, combine overflow-x with the transform property.

HTML
<html>
<head>
    <style>
        .scroll-top {
            overflow-x: auto;
            transform: rotate(180deg);
            height: 150px;
            width: 300px;
            border: 1px solid #000;
        }
        .content {
            transform: rotate(180deg);
        }
    </style>
</head>
<body>
    <div class="scroll-top">
        <div class="content">
         This is a sampel code 
        </div>
    </div>
</body>
</html>
  • The .scroll-top class applies transform: rotate(180deg); to flip the container, placing the scrollbar at the top.
  • The inner .content div reverses the flip to display content correctly.


Next Article

Similar Reads