Question
How to Hide the Scrollbar While Keeping Scrolling in CSS
Question
I want users to be able to scroll through the entire page without showing the scrollbar.
In Google Chrome, I tried:
::-webkit-scrollbar {
display: none;
}
However, Mozilla Firefox and Internet Explorer do not behave the same way.
I also tried:
overflow: hidden;
That hides the scrollbar, but it also disables scrolling.
Is there a way to hide the scrollbar while still allowing the page to scroll, using only CSS or HTML?
Short Answer
By the end of this page, you will understand the difference between hiding overflow and hiding the scrollbar UI, how browser-specific scrollbar support works, and the CSS techniques used to keep scrolling enabled while making the scrollbar invisible.
Concept
Scrolling and scrollbars are related, but they are not the same thing.
- Scrolling is the ability to move through content that is larger than its container.
- The scrollbar is the visual control the browser shows to indicate that scrolling is possible.
A common beginner mistake is using:
overflow: hidden;
This does hide the scrollbar, but it also removes the ability to scroll because it clips the overflowed content.
To keep scrolling enabled, you need CSS that:
- allows overflow to remain scrollable
- hides only the scrollbar visuals
This matters in real programming when building:
- full-screen layouts
- custom carousels
- mobile-style panels
- sidebars with custom designs
- UI components where the default scrollbar does not match the design
The challenge is that scrollbar styling is not fully standardized across all browsers, so different CSS rules are often combined:
::-webkit-scrollbarfor Chrome, Safari, and other WebKit/Blink-based browsersscrollbar-width: none;for Firefox-ms-overflow-style: none;for older Internet Explorer and legacy Edge
A common cross-browser pattern looks like this:
.scroll-container {
overflow: auto;
scrollbar-width: none; /* Firefox */
-ms-overflow-style: none; /* IE and old Edge */
}
.scroll-container::-webkit-scrollbar {
display: none; /* Chrome, Safari, Opera */
}
If you apply the same idea to the body or html element, you can hide the page scrollbar while keeping the page scrollable.
Mental Model
Think of a long document inside a drawer.
- Scrolling means you can slide the document up and down to read more.
- The scrollbar is just the small handle on the side showing your position.
Using overflow: hidden is like locking the drawer shut. The handle disappears, but now you cannot move the document.
Hiding only the scrollbar is like removing the visible handle while still letting the drawer slide normally.
Syntax and Examples
Basic cross-browser pattern
.scroll-area {
overflow: auto;
scrollbar-width: none;
-ms-overflow-style: none;
}
.scroll-area::-webkit-scrollbar {
display: none;
}
What this does
overflow: auto;keeps scrolling available when content is too largescrollbar-width: none;hides the scrollbar in Firefox-ms-overflow-style: none;hides the scrollbar in older IE/Edge::-webkit-scrollbartargets Chrome, Safari, and similar browsers
Example for the whole page
html, body {
overflow: auto;
scrollbar-width: none;
-ms-overflow-style: none;
}
body::-webkit-scrollbar,
html::-webkit-scrollbar {
display: none;
}
This attempts to hide the page scrollbar while still allowing the document to scroll.
Example for a scrollable container
<div class="panel">
<p>Line 1</p>
<p>Line 2</p>
<p>Line 3</p>
<p>Line 4</p>
<p>Line 5</p>
<p>Line 6</p>
<p>Line 7</p>
<p>Line 8</p>
</div>
.panel {
width: 250px;
height: 120px;
overflow: auto;
border: 1px solid #ccc;
padding: 8px;
scrollbar-width: none;
-ms-overflow-style: none;
}
.panel::-webkit-scrollbar {
display: none;
}
The content still scrolls with a mouse wheel, trackpad, keyboard, or touch, but the scrollbar is hidden.
Step by Step Execution
Consider this example:
<div class="box">
<p>A</p>
<p>B</p>
<p>C</p>
<p>D</p>
<p>E</p>
<p>F</p>
</div>
.box {
height: 60px;
overflow: auto;
scrollbar-width: none;
-ms-overflow-style: none;
}
.box::-webkit-scrollbar {
display: none;
}
Step by step
- The
.boxhas a fixed height of60px. - The content inside is taller than
60px. - Because
overflow: auto;is set, the browser allows scrolling. - In Firefox,
scrollbar-width: none;removes the visible scrollbar. - In older IE/Edge,
-ms-overflow-style: none;removes the visible scrollbar. - In Chrome/Safari,
::-webkit-scrollbar { display: none; }hides the scrollbar. - The content still exists and remains scrollable.
What if you used overflow: hidden; instead?
.box {
height: 60px;
overflow: hidden;
}
Then:
- Content beyond
60pxis clipped. - No scrollbar is shown.
- Scrolling is disabled.
- Some content becomes unreachable.
That is why overflow: hidden; is not the correct solution for this problem.
Real World Use Cases
When developers use this
Custom-designed interfaces
Apps sometimes hide native scrollbars to match a minimal visual style.
Horizontal card sliders
A row of cards may scroll sideways on touch devices, but the scrollbar is hidden for a cleaner look.
Full-screen mobile-like layouts
Some web apps mimic native mobile screens where visible scrollbars are unnecessary.
Chat panels or sidebars
A message list or navigation pane may remain scrollable while using custom visual styling.
Embedded widgets
A widget inside another page may need scrolling without showing a browser-default scrollbar that clashes with the design.
Important usability note
Hiding scrollbars can make it less obvious that content is scrollable. In real applications, developers often compensate by using:
- fade effects
- partially cut-off content
- arrows or drag hints
- touch-friendly layouts
- visible spacing cues
Real Codebase Usage
In real projects, developers usually do not apply scrollbar hiding everywhere by default. Instead, they use it selectively.
Common patterns
Utility class pattern
.hide-scrollbar {
scrollbar-width: none;
-ms-overflow-style: none;
}
.hide-scrollbar::-webkit-scrollbar {
display: none;
}
This class can be reused on any scrollable element.
Pairing with a scroll container
.scroll-y {
overflow-y: auto;
}
<div class="scroll-y hide-scrollbar">...</div>
This separates behavior from styling.
Direction-specific scrolling
Developers often hide the scrollbar only for horizontal or vertical regions:
.gallery {
overflow-x: auto;
overflow-y: hidden;
white-space: nowrap;
scrollbar-width: none;
-ms-overflow-style: none;
}
.gallery::-webkit-scrollbar {
display: none;
}
Guarding usability
In mature codebases, teams often avoid hiding scrollbars for long text-heavy sections because discoverability matters.
Component-based styling
In design systems, a reusable scroll container component may include hidden-scrollbar support as an optional modifier rather than a default behavior.
Common Mistakes
1. Using overflow: hidden when scrolling is required
Broken code
.container {
overflow: hidden;
}
Problem
This hides the scrollbar and prevents scrolling.
Fix
.container {
overflow: auto;
scrollbar-width: none;
-ms-overflow-style: none;
}
.container::-webkit-scrollbar {
display: none;
}
2. Only supporting Chrome
Broken code
.container::-webkit-scrollbar {
display: none;
}
Problem
This does not cover Firefox or older IE/Edge.
Fix
Add browser-specific rules:
.container {
scrollbar-width: none;
-ms-overflow-style: none;
}
3. Forgetting to make the element scrollable
Broken code
.container {
scrollbar-width: none;
}
Problem
If there is no overflow: auto, overflow: scroll, or overflow in the content, there is nothing to scroll.
Fix
.container {
overflow: auto;
scrollbar-width: none;
}
4. Applying the rule to the wrong element
For full-page scrolling, styling a nested element may do nothing if the page itself is what scrolls.
Fix
Try applying the rules to html, body, or the actual scroll container.
5. Hiding scrollbars without considering accessibility
Some users rely on visible scroll indicators.
Better approach
- hide scrollbars only where needed
- keep touch, wheel, and keyboard scrolling working
- provide visual cues that more content exists
Comparisons
| Technique | Hides scrollbar | Keeps scrolling | Typical use |
|---|---|---|---|
overflow: hidden | Yes | No | Clip content, prevent scrolling |
overflow: auto | No | Yes | Normal scroll behavior |
overflow: scroll | No | Yes | Always show scrolling area |
scrollbar-width: none | Yes, in Firefox | Yes | Firefox scrollbar hiding |
::-webkit-scrollbar { display: none; } | Yes, in WebKit/Blink browsers | Yes | Chrome/Safari scrollbar hiding |
-ms-overflow-style: none | Yes, in old IE/Edge | Yes | Legacy Microsoft browser support |
overflow: auto vs overflow: hidden
- Use
overflow: autowhen content should remain reachable. - Use
overflow: hiddenwhen extra content should be clipped and inaccessible by scrolling.
Page scrollbar vs container scrollbar
- Page scrollbar: appears when the whole document is taller than the viewport.
- Container scrollbar: appears inside a specific element like a sidebar, modal, or panel.
The same scrollbar-hiding idea works for both, but you must target the correct element.
Cheat Sheet
/* Reusable cross-browser scrollbar hiding */
.hide-scrollbar {
scrollbar-width: none; /* Firefox */
-ms-overflow-style: none; /* IE and old Edge */
}
.hide-scrollbar::-webkit-scrollbar {
display: none; /* Chrome, Safari, Opera */
}
/* Scrollable container */
.box {
overflow: auto;
}
/* Vertical only */
.box {
overflow-y: auto;
overflow-x: hidden;
}
Rules to remember
overflow: hiddendisables scrolling.- Hiding the scrollbar is different from disabling overflow.
- Cross-browser support usually needs multiple CSS rules.
- Apply the styles to the actual element that scrolls.
- For full-page scrolling, try
htmlandbody.
Common cross-browser snippet
html, body {
overflow: auto;
scrollbar-width: none;
-ms-overflow-style: none;
}
html::-webkit-scrollbar,
body::-webkit-scrollbar {
display: none;
}
Edge case
On some systems or browsers, scrollbar behavior depends on OS settings, overlay scrollbars, or browser implementation, so visual results may vary slightly.
FAQ
Can I hide the scrollbar with CSS and still scroll?
Yes. Use overflow: auto or overflow: scroll to keep scrolling enabled, then hide the scrollbar with browser-specific CSS.
Why does overflow: hidden stop scrolling?
Because it clips overflowed content instead of making it scrollable.
Does one CSS rule work in every browser?
No. You usually combine ::-webkit-scrollbar, scrollbar-width: none, and -ms-overflow-style: none for wider support.
Should I apply this to body or html?
Apply it to whichever element is actually scrolling. For full-page layouts, developers often test both html and body.
Is hiding the scrollbar a good idea?
Sometimes, but it can hurt usability because users may not realize more content is available.
Will mouse wheel and touch scrolling still work?
Yes, if scrolling is still enabled with overflow: auto or overflow: scroll.
Can I hide only the horizontal scrollbar?
Yes. For example:
.container {
overflow-x: auto;
overflow-y: hidden;
}
Then apply the scrollbar-hiding rules to that container.
Mini Project
Description
Build a scrollable notes panel that keeps content accessible while hiding the native scrollbar. This demonstrates the practical difference between allowing overflow and visually hiding scrollbar controls.
Goal
Create a vertically scrollable panel whose content can still be read with wheel, touch, or keyboard scrolling, but without showing the visible scrollbar.
Requirements
[ "Create a container with a fixed height so its content overflows.", "Keep vertical scrolling enabled inside the container.", "Hide the scrollbar in Chrome/Safari, Firefox, and older IE/Edge where supported.", "Do not use JavaScript.", "Make sure the content remains readable and reachable." ]
Keep learning
Related questions
Allow Only Numeric Input (0-9) in HTML Input Using jQuery
Learn how to allow only digits 0-9 in an HTML input using jQuery, with examples, validation tips, common mistakes, and best practices.
Apply CSS !important with jQuery .css()
Learn why jQuery .css() cannot set !important and how to use CSSStyleDeclaration.setProperty() to apply inline important styles safely.
CSS ::before and ::after on Input Elements
Learn why CSS ::before and ::after usually do not work on input elements, what replaced elements are, and practical alternatives.