How to hide the Scroll Bars using CSS
In this tutorial, we are going to learn about how to hide scroll bars (horizontally, vertically) in a webpage using the CSS.
Hiding the scroll bars
To hide the scroll bars both horizontally and vertically, we need to add an overflow: hidden
to the parent element.
body{
overflow: hidden;
}
Hiding the scroll bar Horizontally
To hide the horizontal scroll bar, we can use the overflow-x: hidden
property.
body{
overflow-x: hidden;
}
Hiding the scroll bar Vertically
To hide the vertical scroll bar, we can use the overflow-y: hidden
property.
body{
overflow-y: hidden;
}
Note: By adding an
overflow: hidden
it also disables the scrolling functionality, so we can’t able to scroll inside the webpage.
If you want to hide the scroll bar but you still be able to scroll inside the webpage, use the following CSS code.
.container{
width: 200px;
height: 400px;
overflow-y: scroll;
}
.container::-webkit-scrollbar {
display: none; /* Safari and Chrome browsers */
}
.container {
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* mozilla */
}