How to Hide Scrollbar But Still Scroll in CSS?

When the size of an element is fixed and we try to add more and more content to it, the content starts overflowing out of its boundaries.

To avoid this problem, we prefer adding horizontal and vertical scrollbars using the overflow: auto; property so that the content could remain within the element’s boundaries. See the below image:

A div with scroll and scrollbars

But, there may be situations, where you want to keep the content within the element’s boundaries i.e. allow scroll but the scrollbars should be hidden.

To achieve that you have to explicitly hide the scrollbars by setting their display property to none. See the following code example:

    width: 300px;
    height: 150px;
    border: 2px solid red;
    padding: 10px;
::-webkit-scrollbar {
    display: none;  /*Hide scrollbars*/

If you apply the above CSS code to the div element, it will allow you to scroll but no scrollbars will be added to it.

See the following image where the scroll is enabled but no scrollbars are appearing:

Hide Scrollbar But Still Scroll in CSS

Thanks for reading.


  • Manoj Kumar

    Hi, My name is Manoj Kumar. I am a full-stack developer with a passion for creating robust and efficient web applications. I have hands-on experience with a diverse set of technologies, including but not limited to HTML, CSS, JavaScript, TypeScript, Angular, Node.js, Express, React, and MongoDB.

    View all posts