Ever found yourself wanting to remove the browser's default scrollbar from your web page to create a more seamless, modern, or even retro user experience? CSS provides several methods to achieve this, and we're going to explore them in this guide. Let's dive in!
Understanding Scrollbars
Before we delve into removing scrollbars, it's essential to understand what they are and why they exist. Scrollbars are UI elements that allow users to interact with content that doesn't fit within the viewport. They appear on the right side of the screen (or at the bottom on mobile) and provide a visual representation of the content's length and the user's current position.
Why Remove Scrollbars?
There are several reasons why you might want to remove scrollbars from your web page. Some popular use cases include:

- Creating a fullscreen or immersive experience, such as in a presentation or game.
- Achieving a minimalist or flat design aesthetic.
- Improving accessibility by using custom scrollbars or providing alternative navigation methods.
Removing Scrollbars with CSS
CSS offers several properties to control scrollbars. The most common ones are:
overflow
The `overflow` property determines what happens when content overflows its container. Setting it to `hidden` will hide the content that doesn't fit, while `auto` or `scroll` will add scrollbars as needed.
scrollbar-width
The `scrollbar-width` property allows you to set the width of the scrollbar. Setting it to `thin` or `auto` can help reduce its size, but it won't remove it entirely.

::-webkit-scrollbar
This pseudo-element is specific to WebKit-based browsers (like Chrome and Safari) and allows you to style and hide scrollbars. By setting its width and height to 0, you can remove the scrollbar completely.
Removing Scrollbars: The Complete Guide
To remove scrollbars entirely, you'll need to combine the above properties and pseudo-element. Here's a comprehensive example:
```css body { overflow: hidden; -webkit-overflow-scrolling: touch; /* Enables smooth scrolling on mobile */ } ::-webkit-scrollbar { width: 0; height: 0; } ```
This CSS will remove scrollbars from the entire page, including nested elements. However, keep in mind that this might also remove the ability to scroll the page using touch input on mobile devices. The `-webkit-overflow-scrolling: touch;` property ensures that touch scrolling still works.

Styling Custom Scrollbars
If you want to keep scrollbars but style them to match your design, you can use the `::-webkit-scrollbar` pseudo-element along with other CSS properties. Here's an example:
```css ::-webkit-scrollbar { width: 12px; } ::-webkit-scrollbar-track { background: #f1f1f1; } ::-webkit-scrollbar-thumb { background: #888; border-radius: 6px; } ::-webkit-scrollbar-thumb:hover { background: #555; } ```
This CSS will create a custom scrollbar with a track and thumb that match the provided colors and dimensions.
Accessibility Considerations
While removing scrollbars can improve the visual aesthetics of your web page, it's essential to consider accessibility. Users with motor impairments or visual impairments might rely on scrollbars to navigate your content. Providing alternative navigation methods or using custom scrollbars that are easily distinguishable can help maintain accessibility.
Browser Compatibility
Most CSS properties related to scrollbars have good browser compatibility. However, the `::-webkit-scrollbar` pseudo-element is only supported in WebKit-based browsers. For other browsers, you can use JavaScript to detect the browser and apply the appropriate CSS. Here's an example using Modernizr:
```javascript if (Modernizr.scrollbar) { // Apply custom scrollbar CSS for WebKit-based browsers } else { // Apply alternative scrollbar CSS for other browsers } ```
In this guide, we've explored the various methods for removing scrollbars using CSS. By understanding the different CSS properties and pseudo-elements, you can create a more seamless and engaging user experience for your web pages. Happy coding!






















