Javatpoint Logo
Javatpoint Logo

How to hide scrollbar in html

Users can move through content that extends beyond the visible screen area with the help of scrollbars, which are crucial components of web design. To create a simpler and more minimalist user experience, you might want to hide scrollbars in some circumstances.

The goal of this article is to provide your website visitors with a seamless surfing experience by examining several methods for hiding scrollbars in HTML, CSS, and JavaScript.

The aesthetics of your website can be improved by hiding the scrollbars, but it's still necessary to offer alternate navigation options or visual cues for scrollable content. By doing this, you make sure that people with impairments or those who rely on assistive technology may still access the hidden content and use your website efficiently.

To keep your design inclusive, think about including keyboard navigation, explicit instructions, or accessible navigation components.

Scrollbars can be hidden using CSS, which is the most popular and simple approach to do so. To achieve scrollbar hiding, the following CSS properties can be added to the corresponding elements:

a) Disable the vertical scrollbar

You can use the overflow property with the hidden flag to conceal an element's vertical scrollbar. For instance:

This will stop the vertical scrollbar from showing while still enabling scrolling.

b) Hiding the Horizontal Scrollbar: To hide the horizontal scrollbar, use the overflow-x property on the desired element with the hidden setting. For instance:

By doing this, the horizontal scrollbar won't show up but horizontal scrolling will still be possible if necessary.

c) Hiding Both Vertical and Horizontal Scrollbars: You may use the overflow property on the target element to hide both the vertical and horizontal scrollbars. For instance:

The horizontal and vertical scrollbars will both be simultaneously hidden by doing this.

JavaScript Scrollbar Hiding: Depending on user input or other factors, you may occasionally need to dynamically conceal the scrollbars. It is possible to implement this feature using JavaScript.

Here is an example of how to conceal scrollbars using JavaScript:

Change "element-id" to the correct ID of the element you want to change.

Customising Scrollbars: In addition to hiding scrollbars, you can change the way they look to better fit the style of your website.

But keep in mind that not all browsers may consistently provide these characteristics.

For instance, you can alter the colour, width, and other visual characteristics of the scrollbar in browsers that allow these CSS attributes by using::-webkit-scrollbar together with pseudo-elements like::-webkit-scrollbar-thumb,::-webkit-scrollbar-track, and::-webkit-scrollbar-track-piece.

In the above example, we set the width of the scrollbar using `::-webkit-scrollbar` and the background color of the thumb using `::-webkit-scrollbar-thumb`. We also define the background color of the track using `::-webkit-scrollbar-track`.

Additionally, we set a different background color for the thumb when hovered using `::-webkit-scrollbar-thumb:hover`.

Remember to test scrollbar customization across different browsers, as not all browsers support these CSS properties.

In cases where scrollbar customization is not widely supported, it's advisable to rely on alternative design choices or utilize a JavaScript-based custom scrollbar library for consistent results.


Hiding scrollbars can be an effective way to create a sleek and modern user interface. By utilizing CSS and JavaScript techniques, you can easily hide scrollbars and provide a seamless browsing experience to your website visitors. Remember to test your solutions across different browsers to ensure compatibility.

With the right approach, you can create an engaging and visually appealing website while maintaining usability and functionality.

Additionally, customizing scrollbars can add a unique touch to your design, but it's important to consider browser compatibility when implementing such customizations.

Sleek and contemporary user interfaces can be made by effectively hiding scrollbars. You can quickly hide scrollbars and offer a seamless surfing experience to visitors to your website by utilising CSS and JavaScript approaches.

In order to ensure compatibility, don't forget to test your solutions on various browsers. When designing a website, it's possible to keep it useful and usable while yet making it interesting and visually beautiful.

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA