I want to be able to scroll through the whole page, but without the scrollbar being shown.
In Google Chrome it's:
::-webkit-scrollbar {
display: none;
}
But Mozilla Firefox and Internet Explorer don't seem to work like that.
I also tried this in CSS:
overflow: hidden;
That does hide the scrollbar, but I can't scroll any more.
Is there a way I can remove the scrollbar while still being able to scroll the whole page?
With just CSS or HTML, please.
This question is related to
html
css
google-chrome
internet-explorer
firefox
HTML:
<div class="parent">
<div class="child">
</div>
</div>
CSS:
.parent{
position: relative;
width: 300px;
height: 150px;
border: 1px solid black;
overflow: hidden;
}
.child {
height: 150px;
width: 318px;
overflow-y: scroll;
}
Apply CSS accordingly.
Check it here (tested in Internet Explorer and Firefox).
This answer doesn't include the code, so here is the solution from page:
According to the page this approach doesn't need to know the width of the scrollbar ahead of time in order to work and the solution works for all browsers too, and can be seen here.
The good thing is that you are not forced to use padding or width differences to hide the scrollbar.
This is also zoom safe. Padding/width solutions show the scrollbar when zoomed to minimum.
Firefox fix: http://jsbin.com/mugiqoveko/1/edit?output
.element,_x000D_
.outer-container {_x000D_
width: 200px;_x000D_
height: 200px;_x000D_
}_x000D_
.outer-container {_x000D_
border: 5px solid purple;_x000D_
position: relative;_x000D_
overflow: hidden;_x000D_
}_x000D_
.inner-container {_x000D_
position: absolute;_x000D_
left: 0;_x000D_
overflow-x: hidden;_x000D_
overflow-y: scroll;_x000D_
padding-right: 150px;_x000D_
}_x000D_
.inner-container::-webkit-scrollbar {_x000D_
display: none;_x000D_
}
_x000D_
<div class="outer-container">_x000D_
<div class="inner-container">_x000D_
<div class="element">_x000D_
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer vehicula quam nibh, eu tristique tellus dignissim quis. Integer condimentum ultrices elit ut mattis. Praesent rhoncus tortor metus, nec pellentesque enim mattis nec. Nulla vitae turpis ut_x000D_
dui consectetur pellentesque quis vel est. Curabitur rutrum, mauris ut mollis lobortis, sem est congue lectus, ut sodales nunc leo a libero. Cras quis sapien in mi fringilla tempus condimentum quis velit. Aliquam id aliquam arcu. Morbi tristique_x000D_
aliquam rutrum. Duis tincidunt, orci suscipit cursus molestie, purus nisi pharetra dui, tempor dignissim felis turpis in mi. Vivamus ullamcorper arcu sit amet mauris egestas egestas. Vestibulum turpis neque, condimentum a tincidunt quis, molestie_x000D_
vel justo. Sed molestie nunc dapibus arcu feugiat, ut sollicitudin metus sagittis. Aliquam a volutpat sem. Quisque id magna ultrices, lobortis dui eget, pretium libero. Curabitur aliquam in ante eu ultricies._x000D_
</div>_x000D_
</div>_x000D_
</div>
_x000D_
This works for me:
scroll-content {
overflow-x: hidden;
overflow-y: scroll;
}
scroll-content::-webkit-scrollbar {
width: 0;
}
Just set the width of the child's width to 100%, padding to 15 pixels, overflow-x
to scroll and overflow:hidden
for the parent and whatever width you want.
It works perfectly on all major browsers, including Internet Explorer and Edge with the exception of Internet Explorer 8 and lower.
The following was working for me on Microsoft, Chrome and Mozilla for a specific div element:
div.rightsidebar {
overflow-y: auto;
scrollbar-width: none;
-ms-overflow-style: none;
}
div.rightsidebar::-webkit-scrollbar {
width: 0 !important;
}
Adding padding to an inner div
, as in the currently accepted answer, won't work if for some reason you want to use box-model: border-box
.
What does work in both cases is increasing the width of the inner div
to 100% plus the scrollbar's width (assuming overflow: hidden
on the outer div).
For example, in CSS:
.container2 {
width: calc(100% + 19px);
}
In JavaScript, cross-browser:
var child = document.getElementById('container2');
var addWidth = child.offsetWidth - child.clientWidth + "px";
child.style.width = 'calc(100% + ' + addWidth + ')';
It is easy in WebKit, with optional styling:
html {
overflow: scroll;
overflow-x: hidden;
}
::-webkit-scrollbar {
width: 0; /* Remove scrollbar space */
background: transparent; /* Optional: just make scrollbar invisible */
}
/* Optional: show position indicator in red */
::-webkit-scrollbar-thumb {
background: #FF0000;
}
To hide scroll bars for elements with overflowing content use.
.div{
scrollbar-width: none; /* The most elegant way for Firefox */
}
.className::-webkit-scrollbar{
display: none;
}
Everything you've written is correct except "overflow". webkit for Chrome and other browsers
overflow-y: scroll;
or
overflow-y: auto;
For Firefox and Edge
scrollbar-width: none;
or
scrollbar-width: thin;
Another sort of hacky approach is to do overflow-y: hidden
and then manually scroll the element with something like this:
function detectMouseWheelDirection(e) {
var delta = null, direction = false;
if (!e) { // If the event is not provided, we get it from the window object
e = window.event;
}
if (e.wheelDelta) { // Will work in most cases
delta = e.wheelDelta / 60;
} else if (e.detail) { // Fallback for Firefox
delta = -e.detail / 2;
}
if (delta !== null) {
direction = delta > 0 ? -200 : 200;
}
return direction;
}
if (element.addEventListener) {
element.addEventListener('DOMMouseScroll', function(e) {
element.scrollBy({
top: detectMouseWheelDirection(e),
left: 0,
behavior: 'smooth'
});
});
}
There's a great article about how to detect and deal with onmousewheel
events in deepmikoto's blog.
This might work for you, but it is definitively not an elegant solution.
This will be at the body:
<div id="maincontainer" >
<div id="child">this is the 1st step</div>
<div id="child">this is the 2nd step</div>
<div id="child">this is the 3rd step</div>
And this is the CSS:
#maincontainer
{
background: grey;
width: 101%;
height: 101%;
overflow: auto;
position: fixed;
}
#child
{
background: white;
height:500px;
}
This is a divitis-esque solution which nontheless should work for all browsers...
The markup is as follows and needs to be inside something with relative positioning (and its width should be set, for example 400 pixels):
<div class="hide-scrollbar">
<div class="scrollbar">
<div class="scrollbar-inner">
</div>
</div>
</div>
The CSS:
.hide-scrollbar {
overflow: hidden;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
.scrollbar {
overflow-y: scroll;
position: absolute;
top: 0;
left: 0;
right: -50px;
bottom: 0;
}
.scrollbar-inner {
width: 400px;
}
On modern browsers you can use wheel event
:
// Content is the element you want to apply the wheel scroll effect to
content.addEventListener('wheel', function(e) {
const step = 100; // How many pixels to scroll
if (e.deltaY > 0) // Scroll down
content.scrollTop += step;
else // Scroll up
content.scrollTop -= step;
});
You can use the code below to hide the scroll bar, but while still being able to scroll:
.element::-webkit-scrollbar {
width: 0 !important
}
Use:
<div style='overflow:hidden; width:500px;'>
<div style='overflow:scroll; width:508px'>
My scroll-able area
</div>
</div>
This is a trick to somewhat overlap the scrollbar with an overlapping div which doesn't have any scroll bars:
::-webkit-scrollbar {
display: none;
}
This is only for WebKit browsers... Or you could use browser-specific CSS content (if there is any in future). Every browser could have a different and specific property for their respective bars.
For Microsoft Edge use: -ms-overflow-style: -ms-autohiding-scrollbar;
or -ms-overflow-style: none;
as per MSDN.
There is no equivalent for Firefox. Although there is a jQuery plugin to achieve this, http://manos.malihu.gr/tuts/jquery_custom_scrollbar.html
scrollbar-width: none;
works for me
UPDATE:
Firefox now supports hiding scrollbars with CSS, so all major browsers are now covered (Chrome, Firefox, Internet Explorer, Safari, etc.).
Simply apply the following CSS to the element you want to remove scrollbars from:
.container {
overflow-y: scroll;
scrollbar-width: none; /* Firefox */
-ms-overflow-style: none; /* Internet Explorer 10+ */
}
.container::-webkit-scrollbar { /* WebKit */
width: 0;
height: 0;
}
This is the least hacky cross browser solution that I'm currently aware of. Check out the demo.
ORIGINAL ANSWER:
Here's another way that hasn't been mentioned yet. It's really simple and only involves two divs and CSS. No JavaScript or proprietary CSS is needed, and it works in all browsers. It doesn't require explicitly setting the width of the container either, thus making it fluid.
This method uses a negative margin to move the scrollbar out of the parent and then the same amount of padding to push the content back to its original position. The technique works for vertical, horizontal and two way scrolling.
Demos:
Example code for the vertical version:
HTML:
<div class="parent">
<div class="child">
Your content.
</div>
</div>
CSS:
.parent {
width: 400px;
height: 200px;
border: 1px solid #AAA;
overflow: hidden;
}
.child {
height: 100%;
margin-right: -50px; /* Maximum width of scrollbar */
padding-right: 50px; /* Maximum width of scrollbar */
overflow-y: scroll;
}
The following SASS styling should make your scrollbar transparent on most browsers (Firefox is not supported):
.hide-scrollbar {
scrollbar-width: thin;
scrollbar-color: transparent transparent;
&::-webkit-scrollbar {
width: 1px;
}
&::-webkit-scrollbar-track {
background: transparent;
}
&::-webkit-scrollbar-thumb {
background-color: transparent;
}
}
I just wanted to share a combined snippet for hiding the scrollbar that I use when developing. It is a collection of several snippets found on the Internet that works for me:
.container {
overflow-x: scroll; /* For horiz. scroll, otherwise overflow-y: scroll; */
-ms-overflow-style: none;
overflow: -moz-scrollbars-none;
scrollbar-width: none;
}
.container::-webkit-scrollbar {
display: none; /* Safari and Chrome */
}
In addition, Scrolling without scroll bar for all browsers.
CSS
.keep-scrolling {
background-color: #eee;
width: 200px;
height: 100px;
border: 1px dotted black;
overflow-y: scroll; /* Add the ability to scroll y axis*/
}
/* Hide scrollbar for Chrome, Safari and Opera */
.keep-scrolling::-webkit-scrollbar {
display: none;
}
/* Hide scrollbar for IE, Edge and Firefox */
.keep-scrolling {
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
}
SCSS
.keep-scrolling {
background-color: #eee;
width: 200px;
height: 100px;
border: 1px dotted black;
overflow-y: scroll; /* Add the ability to scroll y axis*/
/* Hide scrollbar for IE, Edge and Firefox */
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
/* Hide scrollbar for Chrome, Safari and Opera */
::-webkit-scrollbar {
display: none;
}
}
HTML
<div class="keep-scrolling">
</div>
I had this problem, and it is super simple to fix.
Get two containers. The inner will be your scrollable container and the outer will obviously house the inner:
#inner_container { width: 102%; overflow: auto; }
#outer_container { overflow: hidden }
It is super simple and should work with any browser.
This is how I do it for horizontal scroll; only CSS and works well with frameworks like Bootstrap / col-*. It only needs two extra div
s and the parent with a width
or max-width
set:
You can select the text to make it scroll or scroll it with fingers if you have a touchscreen.
.overflow-x-scroll-no-scrollbar {_x000D_
overflow: hidden;_x000D_
}_x000D_
.overflow-x-scroll-no-scrollbar div {_x000D_
overflow-x: hidden;_x000D_
margin-bottom: -17px;_x000D_
overflow-y: hidden;_x000D_
width: 100%;_x000D_
}_x000D_
.overflow-x-scroll-no-scrollbar div * {_x000D_
overflow-x: auto;_x000D_
width: 100%;_x000D_
padding-bottom: 17px;_x000D_
white-space: nowrap;_x000D_
cursor: pointer_x000D_
}_x000D_
_x000D_
/* The following classes are only here to make the example looks nicer */_x000D_
.row {_x000D_
width: 100%_x000D_
}_x000D_
.col-xs-4 {_x000D_
width: 33%;_x000D_
float: left_x000D_
}_x000D_
.col-xs-3 {_x000D_
width:25%;_x000D_
float:left_x000D_
}_x000D_
.bg-gray {_x000D_
background-color: #DDDDDD_x000D_
}_x000D_
.bg-orange {_x000D_
background-color:#FF9966_x000D_
}_x000D_
.bg-blue {_x000D_
background-color: #6699FF_x000D_
}_x000D_
.bg-orange-light{_x000D_
background-color: #FFAA88_x000D_
}_x000D_
.bg-blue-light{_x000D_
background-color: #88AAFF_x000D_
}
_x000D_
<html><body>_x000D_
<div class="row">_x000D_
<div class="col-xs-4 bg-orange">Column 1</div>_x000D_
<div class="col-xs-3 bg-gray">Column 2</div>_x000D_
<div class="col-xs-4 bg-blue">Column 3</div>_x000D_
</div>_x000D_
<div class="row">_x000D_
<div class="col-xs-4 bg-orange-light">Content 1</div>_x000D_
<div class="col-xs-3 overflow-x-scroll-no-scrollbar">_x000D_
<div>_x000D_
<div>This content too long for the container, so it needs to be hidden but scrollable without scrollbars</div>_x000D_
</div>_x000D_
</div>_x000D_
<div class="col-xs-4 bg-blue-light">Content 3</div>_x000D_
</div>_x000D_
</body></html>
_x000D_
Short version for lazy people:
.overflow-x-scroll-no-scrollbar {_x000D_
overflow: hidden;_x000D_
}_x000D_
.overflow-x-scroll-no-scrollbar div {_x000D_
overflow-x: hidden;_x000D_
margin-bottom: -17px;_x000D_
overflow-y: hidden;_x000D_
width: 100%;_x000D_
}_x000D_
.overflow-x-scroll-no-scrollbar div * {_x000D_
overflow-x: auto;_x000D_
width: 100%;_x000D_
padding-bottom: 17px;_x000D_
white-space: nowrap;_x000D_
cursor:pointer_x000D_
}_x000D_
_x000D_
/* The following classes are only here to make the example looks nicer */_x000D_
.parent-style {_x000D_
width: 100px;_x000D_
background-color: #FF9966_x000D_
}
_x000D_
<div class="parent-style overflow-x-scroll-no-scrollbar">_x000D_
<div>_x000D_
<div>This content too long for the container, so it needs to be hidden but scrollable without scrollbars</div>_x000D_
</div>_x000D_
</div>
_x000D_
I happen to try the above solutions in my project and for some reason I was not able to hide the scroll bar due to div positioning. Hence, I decided to hide the scroll bar by introducing a div that covers it superficially. Example below is for a horizontal scroll bar:
<div id="container">
<div id="content">
My content that could overflow horizontally
</div>
<div id="scroll-cover">
</div>
</div>
Corresponding CSS is as follows:
#container{
width: 100%;
height: 100%;
overflow: hidden;
position: relative;
}
#content{
width: 100%;
height: 100%;
overflow-x: scroll;
}
#scroll-cover{
width: 100%;
height: 20px;
position: absolute;
bottom: 0;
background-color: #fff; /*change this to match color of page*/
}
This works for me with simple CSS properties:
.container {
-ms-overflow-style: none; /* Internet Explorer 10+ */
scrollbar-width: none; /* Firefox */
}
.container::-webkit-scrollbar {
display: none; /* Safari and Chrome */
}
For older versions of Firefox, use: overflow: -moz-scrollbars-none;
Just use following three lines and your problem will be solved:
#liaddshapes::-webkit-scrollbar {
width: 0 !important;
}
Where liaddshapes is the name of the div where scroll is coming.
This tricky solution works even on old IE web browser
It's a workaround to the [ vertical scrollbar ]
<html>
<head>
<style>
html,
body {
overflow: -moz-scrollbars-vertical;
overflow-x: hidden;
overflow-y: hidden;
height: 100%;
margin: 0;
}
</style>
</head>
<body id="body" style="overflow:auto;height:100%" onload="document.getElementById('body').style.width=document.body.offsetWidth+20+'px'">
<!--your stuff here-->
</body>
</html>
Just try it: jsfiddle
As of December 11th 2018 (Firefox 64 and above), the answer to this question is very simple indeed as Firefox 64+ now implements the CSS Scrollbar Styling spec.
Just use the following CSS:
scrollbar-width: none;
Firefox 64 release note link here.
Hide both horizontal and vertical scroll bars.
HTML
<div id="container1">
<div id="container2">
<pre>
Select from left and drag to right to scroll this very long sentence. This should not show scroll bar at bottom or on the side. Keep scrolling .......... ............ .......... ........... This Fiddle demonstrates that scrollbar can be hidden. ..... ..... ..... .....
</pre>
</div>
<div>
CSS
* {
margin: 0;
}
#container1 {
height: 50px;
width: 100%;
overflow: hidden;
position: relative;
}
#container2 {
position: absolute;
top: 0px;
bottom: -15px;
left: 0px;
right: -15px;
overflow: auto;
}
Use:
#subparent {
overflow: hidden;
width: 500px;
border: 1px rgba(0, 0, 0, 1.00) solid;
}
#parent {
width: 515px;
height: 300px;
overflow-y: auto;
overflow-x: hidden;
opacity: 10%;
}
#child {
width: 511px;
background-color: rgba(123, 8, 10, 0.42);
}
<body>
<div id="subparent">
<div id="parent">
<div id="child">
<!- Code here for scroll ->
</div>
</div>
</div>
</body>
My problem: I don't want any style in my HTML content. I want my body directly scrollable without any scrollbar, and only a vertical scroll, working with CSS grids for any screen size.
The box-sizing value impact padding or margin solutions, they works with box-sizing:content-box.
I still need the "-moz-scrollbars-none" directive, and like gdoron and Mr_Green, I had to hide the scrollbar. I tried -moz-transform
and -moz-padding-start
, to impact only Firefox, but there was responsive side effects that needed too much work.
This solution works for HTML body content with "display: grid" style, and it is responsive.
/* Hide HTML and body scroll bar in CSS grid context */
html, body {
position: static; /* Or relative or fixed ... */
box-sizing: content-box; /* Important for hidding scrollbar */
display: grid; /* For CSS grid */
/* Full screen */
width: 100vw;
min-width: 100vw;
max-width: 100vw;
height: 100vh;
min-height: 100vh;
max-height: 100vh;
margin: 0;
padding: 0;
}
html {
-ms-overflow-style: none; /* Internet Explorer 10+ */
overflow: -moz-scrollbars-none; /* Should hide the scroll bar */
}
/* No scroll bar for Safari and Chrome */
html::-webkit-scrollbar,
body::-webkit-scrollbar {
display: none; /* Might be enough */
background: transparent;
visibility: hidden;
width: 0px;
}
/* Firefox only workaround */
@-moz-document url-prefix() {
/* Make HTML with overflow hidden */
html {
overflow: hidden;
}
/* Make body max height auto */
/* Set right scroll bar out the screen */
body {
/* Enable scrolling content */
max-height: auto;
/* 100vw +15px: trick to set the scroll bar out the screen */
width: calc(100vw + 15px);
min-width: calc(100vw + 15px);
max-width: calc(100vw + 15px);
/* Set back the content inside the screen */
padding-right: 15px;
}
}
body {
/* Allow vertical scroll */
overflow-y: scroll;
}
Use this to hide the scrollbar but keep functionality:
.example::-webkit-scrollbar {
display: none;
}
Hide scrollbar for IE, Edge and Firefox
.example {
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
}
Use
function reloadScrollBars() {
document.documentElement.style.overflow = 'auto'; // Firefox, Chrome
document.body.scroll = "yes"; // Internet Explorer only
}
function unloadScrollBars() {
document.documentElement.style.overflow = 'hidden'; // firefox, chrome
document.body.scroll = "no"; // Internet Explorer only
}
Call these functions for any point you want to load or unload or reload the scrollbars. It is still scrollable in Chrome as I tested it in Chrome, but I am not sure of the other browsers.
Another simple working fiddle:
#maincontainer {
background: orange;
width: 200px;
height: 200px;
overflow: hidden;
}
#childcontainer {
background: yellow;
position: relative;
width: 200px;
height: 200px;
top: 20px;
left: 20px;
overflow: auto;
}
Overflow hidden on the parent container, and overflow auto on the child container. Simple.
This works for me cross-browser. However, this doesn't hide native scrollbars on mobile browsers.
In SCSS
.hide-native-scrollbar {
scrollbar-width: none; /* Firefox 64 */
-ms-overflow-style: none; /* Internet Explorer 11 */
&::-webkit-scrollbar { /** WebKit */
display: none;
}
}
In CSS
.hide-native-scrollbar {
scrollbar-width: none; /* Firefox 64 */
-ms-overflow-style: none; /* Internet Explorer 11 */
}
.hide-native-scrollbar::-webkit-scrollbar { /** WebKit */
display: none;
}
Source: Stackoverflow.com