Hide Scrollbar in CSS (and Style a Custom Scrollbar)
Contents
- Hide the scrollbar, keep scrolling
- Hiding scrollbars
- scrollbar-width: none
- Hide the scrollbar on the whole page
- Hide the scrollbar and disable scrolling
- Hide only the horizontal scrollbar
- Stop the layout from jumping: scrollbar-gutter
- Styling a custom scrollbar
- The standard way: scrollbar-color and scrollbar-width
- More control with ::-webkit-scrollbar
- Hidden scrollbars and usability
- FAQ
To hide the scrollbar but keep scrolling, set scrollbar-width: none on the scrolling element. Add the ::-webkit-scrollbar rule as a fallback for older browsers:
Hide the scrollbar, keep scrolling
.no-scrollbar {
overflow: auto;
scrollbar-width: none; /* all modern browsers */
}
.no-scrollbar::-webkit-scrollbar {
display: none; /* older Chrome and Safari */
}
Demo:
This box has a custom thin scrollbar.
Scroll down to see it.
The thumb is blue and the track is light.
It uses the standard scrollbar-color and scrollbar-width properties.
That's it.
The top row scrolls sideways with no scrollbar; the box below scrolls with a thin, blue custom scrollbar.
Hiding scrollbars
scrollbar-width: none
scrollbar-width is the standard property, supported in Firefox, Chrome and Edge (since version 121) and Safari (since 18.2). none hides the scrollbar, but the element still scrolls with the mouse wheel, touch, keyboard and trackpad. The ::-webkit-scrollbar rule only matters for older Chrome and Safari versions.
Hide the scrollbar on the whole page
Apply it to html, which is the element that scrolls the page. Think twice before doing this: the scrollbar is how many people see how long a page is and where they are in it.
html {
scrollbar-width: none;
}
html::-webkit-scrollbar {
display: none;
}
Hide the scrollbar and disable scrolling
overflow: hidden removes the scrollbar and stops the user from scrolling. Content that doesn’t fit is cut off. This is what you want for a background page while a modal is open.
body.modal-open {
overflow: hidden;
}
Hide only the horizontal scrollbar
A horizontal scrollbar on the whole page usually means something is wider than the screen: an image, a long URL, a 100vw element. Find it and fix it rather than hiding it. If you just need to clip sideways overflow, use overflow-x: clip: unlike hidden, it doesn’t create a scroll container, so position: sticky keeps working inside it.
body {
overflow-x: clip; /* no horizontal scrollbar, vertical scrolling unchanged */
}
/* Find the culprit: outline everything wider than the screen */
* {
outline: 1px solid red;
}
Stop the layout from jumping: scrollbar-gutter
When a page goes from fitting on screen to scrolling (or when you lock scrolling for a modal), the scrollbar appears or disappears and the whole layout shifts sideways. scrollbar-gutter: stable always reserves the space for it.
html {
scrollbar-gutter: stable;
}
Styling a custom scrollbar
The standard way: scrollbar-color and scrollbar-width
Two properties, supported in all modern browsers: scrollbar-color takes the thumb color and then the track color, and scrollbar-width takes auto, thin or none. They’re inherited, so setting them on html styles every scrollbar on the page.
html {
scrollbar-color: #94a3b8 transparent;
scrollbar-width: thin;
}
/* Dark mode */
html.dark {
scrollbar-color: #475569 transparent;
}
More control with ::-webkit-scrollbar
The ::-webkit-scrollbar pseudo-elements allow rounded thumbs, exact sizes and hover states, but only in Chrome, Edge and Safari. In Chrome and Edge 121+, they’re ignored on any element that also has scrollbar-color or scrollbar-width, so use one approach per element. There’s also a custom scrollbar demo in CSS Tips.
.custom::-webkit-scrollbar {
width: 10px;
}
.custom::-webkit-scrollbar-track {
background: #f1f5f9;
}
.custom::-webkit-scrollbar-thumb {
background: #94a3b8;
border: 2px solid #f1f5f9; /* creates padding around the thumb */
border-radius: 999px;
}
.custom::-webkit-scrollbar-thumb:hover {
background: #64748b;
}
Hidden scrollbars and usability
Hiding a scrollbar removes the only hint that there’s more content, and mouse users without a trackpad may not be able to scroll sideways at all. If you hide one:
- Show that content continues: let the last item peek out, or add a fade at the edge.
- Add arrow buttons for horizontal scrollers.
- Make the area keyboard-scrollable with
tabindex="0"if it doesn’t contain focusable elements. - Use scroll snap so items stop in a sensible place.
FAQ
How do I hide the scrollbar but still scroll?
Use scrollbar-width: none on the scrolling element, plus ::-webkit-scrollbar { display: none; } for older browsers. Don’t use overflow: hidden, which disables scrolling.
Why is my scrollbar still showing?
You’re probably targeting the wrong element. For the page, it’s html, not body or a wrapper. For a component, it must be the element that has overflow: auto or scroll.
Does hiding the scrollbar affect SEO?
No. Search engines don’t look at scrollbars, and content inside a scroll container is still indexed.
Can I hide the scrollbar until the user hovers?
Yes: set scrollbar-color: transparent transparent by default and give it real colors on :hover. The space stays reserved, so nothing shifts.