1835

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Oussama el Bachiri
  • 18,687
  • 3
  • 15
  • 22
  • 1
    does webkit-scrollbar doesn't work on other browser? – Franz Oct 02 '20 at 01:31
  • Adding `::-webkit-scrollbar` is changing the background color of section where the data ends. Even after adding `background-color` property to white, it doesnot change anything – Priya Apr 28 '22 at 13:29

42 Answers42

1043

Just a test which is working fine.

#parent{
    width: 100%;
    height: 100%;
    overflow: hidden;
}

#child{
    width: 100%;
    height: 100%;
    overflow-y: scroll;
    padding-right: 17px; /* Increase/decrease this value for cross-browser compatibility */
    box-sizing: content-box; /* So the width will be 100% + 17px */
}

Working Fiddle

JavaScript:

Since the scrollbar width differs in different browsers, it is better to handle it with JavaScript. If you do Element.offsetWidth - Element.clientWidth, the exact scrollbar width will show up.

JavaScript Working Fiddle

Or

Using Position: absolute,

#parent{
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: relative;
}

#child{
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: -17px; /* Increase/Decrease this value for cross-browser compatibility */
    overflow-y: scroll;
}

Working Fiddle

JavaScript Working Fiddle

Information:

Based on this answer, I created a simple scroll plugin.

Community
  • 1
  • 1
Mr_Green
  • 40,727
  • 45
  • 159
  • 271
  • 28
    In your last "working fiddle" I've seen too many `!important` so I've remove them all : http://jsfiddle.net/5GCsJ/954/ – Roko C. Buljan May 06 '14 at 19:23
  • 57
    This approach won't cover all browsers, and will be very specific to the browser's version you are working with during the development. – Itsik Avidan Oct 22 '14 at 12:23
  • 20
    Why complicate and calculate scrollbar width? Just set `box-sizing: border-box; width: calc(100% + 50px);` and the same value for padding. No browser has 50px scrollbar width/height, so it should simply cover them all... – Robert Koritnik Jun 07 '17 at 08:54
  • @RobertKoritnik I have no problems with your idea, but the way it's written just makes me want to scream "Challenge Accepted!" at the top of my lungs and make a browser with the fluffiest scrollbars – Brian Davis Nov 11 '22 at 21:23
  • This is the most highly upvoted wrong answer I've ever seen – Glenn Maynard Jun 20 '23 at 05:00
  • @GlennMaynardit it is not wrong maybe outdated. – Mr_Green Jun 21 '23 at 08:37
821

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;

joeybab3
  • 295
  • 2
  • 7
  • 24
Hristo Eftimov
  • 13,845
  • 13
  • 50
  • 77
  • 23
    For me, `overflow: -moz-scrollbars-none` hides the scrollbars in Firebox but also disables scrolling. Can you provide a demo where this is working for you? – chipit24 Aug 26 '16 at 21:20
  • 4
    Unfortunately the `-moz-scrollbars-none` property is deleted for the newest Firefox versions: https://developer.mozilla.org/en-US/docs/Web/CSS/overflow – Hristo Eftimov Dec 14 '16 at 09:01
  • 4
    Since iOS8, this doesn't work when used with `-webkit-overflow-scrolling: touch` – aleclarson Jun 05 '17 at 18:09
  • @aleclarson I didn't know that. I will test that, will check for a solution and will update my post. thanks :) – Hristo Eftimov Jun 05 '17 at 18:36
  • 4
    For obsolete Firefox `-moz-scrollbars-none` you can use `@-moz-document url-prefix() { .container { overflow: hidden; } }`. See https://stackoverflow.com/questions/952861/targeting-only-firefox-with-css/953491#953491. – Martin Ždila Jun 22 '17 at 08:30
  • 18
    I have updated my answer with the latest support for Firefox :) – Hristo Eftimov Apr 01 '19 at 06:47
  • `scrollbar-width: none` doesn't work for me in Firefox, neither `scrollbar-width: 0`. I don't think that you can change the width of the scrollbar in Firefox. – BarryCap Jun 15 '21 at 13:13
  • But adding `::-webkit-scrollbar` is changing the background color of section where the data ends. Even after adding `background-color` property to white, it doesnot change anything – Priya Apr 28 '22 at 13:24
  • This pseudo element ::-webkit-scrollbar works fine in VS but does not show when deployed/published on server. I am not understanding what to do. Did anyone face the similar porblem? – Priya May 04 '22 at 22:04
  • I'd also mention, that you must have `overflow: scroll` for that to work/hide out-of-the-bounds part of content. – Kostiantyn Ko Nov 22 '22 at 23:37
  • This hides both vertical and horizontal scrollbars while keeping the functionality. Is there a way to hide only the vertical scrollbar while keeping the function as well as keeping the horizontal scrollbar visible? – Muaz Aug 16 '23 at 06:06
  • 1
    Solved my problem ... – Vibhu kumar Aug 20 '23 at 07:13
607

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;
}
Artur INTECH
  • 6,024
  • 2
  • 37
  • 34
Anirban Bhui
  • 6,373
  • 1
  • 11
  • 15
  • 1
    tried this in `cordova` app, worked fine. had to apply `overflow:scroll` to element. – Kishor Pawar Nov 30 '15 at 06:52
  • 77
    Does not works on Firefox, Quite obvious as this purely states webkit. Thanks :) – Zohair Jan 17 '17 at 07:22
  • 6
    works excellent in Electron apps as expected since they're chromium. +1 thanks :D – rococo Apr 30 '17 at 06:58
  • Since iOS8, this doesn't work when used with `-webkit-overflow-scrolling: touch` – aleclarson Jun 05 '17 at 18:09
  • In electron, was having issue with the scrollbar always showing, then 2 scrollbars when scroll was needed, the above just removes all scroll bars.. fixed by applying to only `html` e.g: `html::-webkit-scrollbar` – Lawrence Cherone Feb 16 '18 at 16:15
  • 6
    it works with chrome. but does not work with mozilla firefox. – romal tandel Feb 28 '18 at 04:11
  • **ALSO,** If you would like to alternatively hide **x-scrollbar**, you can add: `height: 0px;` to `::-webkit-scrollbar` – Austin Perez Oct 12 '18 at 17:56
  • curiously, hiding a horizontal scrollbar in Chrome causes it to add some kind of padding to the bottom that can mess up flexbox align-items (only shows up in green when hovering inspect element) – Andy Oct 10 '21 at 04:38
579

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;
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Richrd
  • 6,722
  • 1
  • 17
  • 12
104

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Arpit Singh
  • 3,387
  • 2
  • 17
  • 11
  • http://www.ictacademie.info/oussamaelbachiri/ this site @Oussama Dobby uses media='screen' and then '::-webkit-scrollbar' property for css – Arpit Singh May 21 '13 at 13:24
  • And what are thow specific css properties? – Oussama el Bachiri May 21 '13 at 13:25
  • either a hacky layout or jquery is an alternative – Arpit Singh May 21 '13 at 13:31
  • Your first solution gives me this problem s24.postimg.org/idul8zx9w/Naamloos.jpg And what do you mean by hacky layout @ArpitSingh – Oussama el Bachiri May 21 '13 at 13:48
  • 5
    The following allowed me to enable native scrolling in Cordova with jQuery Mobile 1.4 on iOS7 & iOS8 **// CSS** `::-webkit-scrollbar { display: none; } .ui-content { -webkit-overflow-scrolling: touch; }` **// jQuery Mobile onMobileInit()** `$.mobile.touchOverflowEnabled = true;` – Ryan Williams Nov 07 '14 at 06:49
  • This makes it much easier than I thought. But how do you make IE understand that these are 2 different things: overflow-y:scroll; overflow-x:visible; D: – user1566694 Aug 22 '18 at 15:30
72

In addition, scrolling without a 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 the y axis */
}

/* Hide the scrollbar for Chrome, Safari and Opera */
.keep-scrolling::-webkit-scrollbar {
  display: none;
}

/* Hide the scrollbar for Internet Explorer, Edge and Firefox */
.keep-scrolling {
  -ms-overflow-style: none;  /* Internet Explorer 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 the y axis */

    /* Hide the scrollbar for Internet Explorer, Edge and Firefox */
    -ms-overflow-style: none;  /* Internet Explorer and Edge */
    scrollbar-width: none;  /* Firefox */

    /* Hide the scrollbar for Chrome, Safari and Opera */
    &::-webkit-scrollbar {
       display: none;
    }
}

HTML

<div class="keep-scrolling">
</div>
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Majedur
  • 3,074
  • 1
  • 30
  • 43
43

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 */
}
Arthur
  • 3,056
  • 7
  • 31
  • 61
Wael Khalifa
  • 895
  • 7
  • 17
  • 4
    This is the best answer IMO. Here's the source where I found out how to hide the scroll bar while maintaining the functionality for each of the browsers mentioned. https://www.w3schools.com/howto/howto_css_hide_scrollbars.asp – Webalation Nov 23 '21 at 18:58
34

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,
.outer-container {
  width: 200px;
  height: 200px;
}
.outer-container {
  border: 5px solid purple;
  position: relative;
  overflow: hidden;
}
.inner-container {
  position: absolute;
  left: 0;
  overflow-x: hidden;
  overflow-y: scroll;
  padding-right: 150px;
}
.inner-container::-webkit-scrollbar {
  display: none;
}
<div class="outer-container">
  <div class="inner-container">
    <div class="element">
      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
      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
      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
      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.
    </div>
  </div>
</div>
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Timo Kähkönen
  • 11,962
  • 9
  • 71
  • 112
  • This wont work for all browsers... Only webkit browsers. You're using a webkit-specific selector `::-webkit-scrollbar {}` – tdc Feb 08 '16 at 21:36
  • I tested it in all new browsers before I answered to the question. Also FF. It has happenned some changes in FF? – Timo Kähkönen Feb 09 '16 at 02:13
  • I updated the answer. It seems that adding `padding-right: 150px;` fixes it. Tested in FF, Chrome, Safari and Edge. Works also in low zoom levels due to big right-padding. – Timo Kähkönen Feb 09 '16 at 02:35
  • 2
    Edge, IE 11, IE10 (maybe lower also) support `html { -ms-overflow-style: none;}`. In these browsers there is no need to use padding-hack. – Timo Kähkönen Aug 30 '16 at 11:54
  • Had to use @Timo's answer and `overflow-y: scroll` to get scroll behavior but hidden (just like Chrome) to make it work on Edge23. – jojo Sep 27 '16 at 20:31
  • Since iOS8, this doesn't work when used with `-webkit-overflow-scrolling: touch` – aleclarson Jun 05 '17 at 18:10
  • This is a great answer! The only caveat is that the width of the element must be known and set in pixels (percentages won't work) – Richrd Aug 31 '18 at 16:18
32

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Innodel
  • 1,416
  • 12
  • 16
32

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;
}
Community
  • 1
  • 1
Murhaf Sousli
  • 12,622
  • 20
  • 119
  • 185
24

Just write this code:

::-webkit-scrollbar {
  width: 0px;
}

Or

::-webkit-scrollbar {
  display: none;
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Visal
  • 397
  • 1
  • 3
  • 10
19

This worked for me

div {
  -ms-overflow-style: none; /* Edge, Internet Explorer */
  scrollbar-width: none; /* Firefox */
  overflow-y: scroll;
}

// hides scrollbars while allowing to scroll
div::-webkit-scrollbar {
  display: none; /* Chrome, Safari, Opera */
}
Eliran Assaraf
  • 339
  • 2
  • 5
16
scrollbar-width: none; 

works for me.

Ramesh R
  • 7,009
  • 4
  • 25
  • 38
Sensei Zaid
  • 323
  • 2
  • 6
  • 1
    no mush support for this cross-browser at the time I'm posting https://caniuse.com/?search=scrollbar-width – Samih A Jul 06 '22 at 10:25
14

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;
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Meloman
  • 3,558
  • 3
  • 41
  • 51
13
.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;
11

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.

Chris
  • 4,450
  • 3
  • 38
  • 49
11

To hide scroll bars for elements with overflowing content use.

.div{

  scrollbar-width: none; /* The most elegant way for Firefox */
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Alvin Moyo
  • 200
  • 1
  • 9
  • 1
    The support is practically non existent except for FF as you mentioned with is too little for what the OP asked for. Check https://caniuse.com/#feat=mdn-css_properties_scrollbar-width – Adrien May 07 '20 at 13:00
  • @Adrien Well, the Original question stated that they have a solution for other browsers. (But Mozilla Firefox and Internet Explorer don't seem to work like that) he says, that is the reason I gave the Firefox Solution. – Alvin Moyo May 19 '20 at 00:03
  • I found this worked well when combined with the equivalent: div::-webkit-scrollbar { display: none; } for Webkit / Chrome. – Sean Halls May 25 '20 at 20:22
10

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).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mischa
  • 1,303
  • 12
  • 24
9

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;
});
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Doua Beri
  • 10,612
  • 18
  • 89
  • 138
  • This is the answer I was looking for. Thanks. I used `overflow: hidden` and this code, for the `mat-card-content` (in angular 5, of course) to be scrollable and these solved my problem. Note: I used `e.deltaY` as my `step` and it worked like normal scrolling, so I think for normally scrolling but with scrollbar hidden, this is the best match. – imans77 Feb 05 '19 at 15:24
  • 1
    the page linked here warns that this approach is not appropriate? – jnnnnn May 07 '19 at 01:28
7

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user43353
  • 105
  • 2
  • 7
7

Use:

CSS

#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);
}

HTML

<body>
    <div id="subparent">
        <div id="parent">
            <div id="child">
                <!- Code here for scroll ->
            </div>
        </div>
     </div>
</body>
Community
  • 1
  • 1
Owais
  • 81
  • 1
  • 6
  • Not sure why this was downvoted, but I just upvoted it as it does go in the right direction, the other solutions didn't really work well in my case. overflow-x: hidden; + overflow-y: scroll; is what did the trick, along with the >100% width (110% in my case worked nicely). – dAngelov Apr 26 '15 at 18:23
  • 1
    it's the same thing as the most upvoted sollution: trying to hide the scrollbar. this is not ideal because it varies with the browser – mwm Jan 29 '18 at 17:48
7

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;
  }
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Alexander
  • 396
  • 1
  • 9
  • 19
6

This works for me:

scroll-content {
    overflow-x: hidden;
    overflow-y: scroll;
}

scroll-content::-webkit-scrollbar {
    width: 0;
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
mangesh
  • 355
  • 4
  • 13
5

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>
</div>

And this is the CSS:

#maincontainer
{
    background: grey;
    width: 101%;
    height: 101%;
    overflow: auto;
    position: fixed;
}

#child
{
    background: white;
    height: 500px;
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Hilla
  • 67
  • 1
  • 2
5

This is how I do it for horizontal scroll; only CSS and works well with frameworks like Bootstrap / col-*. It only needs two extra divs 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 {
    overflow: hidden;
}
.overflow-x-scroll-no-scrollbar div {
    overflow-x: hidden;
    margin-bottom: -17px;
    overflow-y: hidden;
    width: 100%;
}
.overflow-x-scroll-no-scrollbar div * {
    overflow-x: auto;
    width: 100%;
    padding-bottom: 17px;
    white-space: nowrap;
    cursor: pointer
}

/* The following classes are only here to make the example looks nicer */
.row {
    width: 100%
}
.col-xs-4 {
    width: 33%;
    float: left
}
.col-xs-3 {
    width:25%;
    float:left
}
.bg-gray {
    background-color: #DDDDDD
}
.bg-orange {
    background-color:#FF9966
}
.bg-blue {
    background-color: #6699FF
}
.bg-orange-light{
    background-color: #FFAA88
}
.bg-blue-light{
    background-color: #88AAFF
}
<html><body>
  <div class="row">
    <div class="col-xs-4 bg-orange">Column 1</div>
    <div class="col-xs-3 bg-gray">Column 2</div>
    <div class="col-xs-4 bg-blue">Column 3</div>
  </div>
  <div class="row">
    <div class="col-xs-4 bg-orange-light">Content 1</div>
    <div class="col-xs-3 overflow-x-scroll-no-scrollbar">
      <div>
        <div>This content too long for the container, so it needs to be hidden but scrollable without scrollbars</div>
      </div>
    </div>
    <div class="col-xs-4 bg-blue-light">Content 3</div>
  </div>
</body></html>

Short version for lazy people:

.overflow-x-scroll-no-scrollbar {
    overflow: hidden;
}
.overflow-x-scroll-no-scrollbar div {
  overflow-x: hidden;
  margin-bottom: -17px;
  overflow-y: hidden;
  width: 100%;
}
.overflow-x-scroll-no-scrollbar div * {
  overflow-x: auto;
  width: 100%;
  padding-bottom: 17px;
  white-space: nowrap;
  cursor:pointer
}

/* The following classes are only here to make the example looks nicer */
.parent-style {
    width: 100px;
    background-color: #FF9966
}
<div class="parent-style overflow-x-scroll-no-scrollbar">
  <div>
    <div>This content too long for the container, so it needs to be hidden but scrollable without scrollbars</div>
  </div>
</div>
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jean
  • 4,911
  • 3
  • 29
  • 50
  • Thanks, I tried, it works great. One thing is it's better to change `margin-bottom` to be `padding-bottom` but with the same value. This will not eat up below space for element at the bottom. It prevents overlapping. – haxpor Mar 28 '17 at 03:16
  • @haxpor The `margin-bottom` is negative, I think it cannot be changed to a `padding-bottom`, that cannot handle negative values – Jean Mar 28 '17 at 16:35
5

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;
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Lucile Fievet
  • 509
  • 5
  • 9
5
.your-overflow-scroll-class::-webkit-scrollbar {
  ...
  width: 0.5rem; //only hide the vertical scrollbar
  height: 0px; //only hide the horizontal scrollbar
}
4

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 + ')';
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
herman
  • 11,740
  • 5
  • 47
  • 58
4

You can use the code below to hide the scroll bar, but while still being able to scroll:

.element::-webkit-scrollbar { 
    width: 0 !important 
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Tienanhvn
  • 239
  • 5
  • 9
3

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;
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
3

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">
     &nbsp; 
  </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*/
}
Adam Ranganathan
  • 1,691
  • 1
  • 17
  • 25
3

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 */
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
stamat
  • 1,832
  • 21
  • 26
2

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 is hidden on the parent container, and overflow is auto on the child container. Simple.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
geoyws
  • 3,326
  • 3
  • 35
  • 47
  • This doesn't hide the scrollbar, it just pushes it out of view with the "left" value. – robertmiles3 Aug 01 '14 at 14:42
  • @robertmiles3 isn't that the same thing? hiding and not being able to view? – Bryan Willis Jun 28 '15 at 16:55
  • 1
    @robertmiles3 the selected answer above does the same thing from the right. Seems like all solutions are hacky until FIrefox decides to allow for CSS to hide scrollbars again. http://blogs.msdn.com/b/kurlak/archive/2013/11/03/hiding-vertical-scrollbars-with-pure-css-in-chrome-ie-6-firefox-opera-and-safari.aspx – geoyws Jun 29 '15 at 01:46
  • I have to agree. This is a similar solution proposed by the accepted answer. If it works it works. upvoted – JSON Nov 21 '17 at 17:09
2

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Gark Garcia
  • 450
  • 6
  • 14
1

This tricky solution works even on old Internet Explorer web browsers.

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
PYK
  • 3,674
  • 29
  • 17
1

I know this is a really old question, but here is a cool cross-browser solution utilizing only HTML and CSS.

HTML:

  <div class="barrel">
    <div class="clipper">
        <p class="clippercontent">Lorem</p>
    </div>
    <div id='navcontainer'>
      <p class="navcontent" >I want to be able to scroll through the whole page, but without the scrollbar being shown. Is there a way I can remove the scrollbar while still being able to scroll the whole page? With just CSS or HTML, please.
     </p>
    </div>
  </div>

Principle: The #navcontainer will house our .navcontent, and will have scrollbars. The .barrel will hide the scrollbar of the #navcontainer.

CSS:

.barrel{
  border: 0.8px solid #110011;
  position: relative;
  overflow: hidden;
}
.barrel #navcontainer{
  overflow: scroll; overflow-y: hidden;
  position: absolute;/* absolute positioned contents will not affect their parents */
  top: 0; left: 0; right: 0;
  white-space: nowrap;
}
/* style .clipper and .clippercontent, as a structural-image of #navcontainer and .navcontent respectively This will help .barrel have the same height as the #navcontainer */
.barrel .clipper{
  overflow: hidden;
  width: 0px;
  white-space: nowrap;
}
.navcontent, .clippercontent{
  padding: 3px 1px;
}
Eazicoding
  • 191
  • 9
1

I added this and it's working for me

-ms-overflow-style: none;  /* IE and Edge */
scrollbar-width: none;  /* Firefox */

Ref : https://www.w3schools.com/howto/howto_css_hide_scrollbars.asp

Ismail Hamdach
  • 127
  • 3
  • 8
1

Simply add this to your CSS file:

"&::-webkit-scrollbar": {
  display: "none",
  width: 0
},
"-ms-oveflow-style": "none" /* Internet Explorer and Edge */,
"scrollbar-width": "none" /* Firefox */,
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sehrish Waheed
  • 1,230
  • 14
  • 17
  • It doesn't look credible. Why the double quotes around, e.g., `&::-webkit-scrollbar`? What are they supposed to achieve? In any case, an explanation would be in order. E.g., what is the idea/gist? From [the Help Center](https://stackoverflow.com/help/promotion): *"...always explain why the solution you're presenting is appropriate and how it works"*. Please respond by [editing (changing) your answer](https://stackoverflow.com/posts/73202552/edit), not here in comments (****** ***without*** ****** "Edit:", "Update:", or similar - the answer should appear as if it was written today). – Peter Mortensen Jan 09 '23 at 20:56
  • It seems to be recycling some of the previous answers, but with unexplained changes. Is there any merit to this answer? – Peter Mortensen Jan 09 '23 at 21:01
  • The [W3C CSS Validator](https://jigsaw.w3.org/css-validator/) complains: `4 Parse Error "&::-webkit-scrollbar": { display: "none", width: 0 }` and `6 Parse Error }, "-ms-oveflow-style": "none" /* Internet Explorer and Edge */, "scrollbar-width": "none" /* Firefox */,` – Peter Mortensen Jan 09 '23 at 21:30
  • Is this a completely bogus answer? – Peter Mortensen Jan 09 '23 at 21:30
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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
0

Hide both horizontal and vertical scroll bars.

See Fiddle here

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;
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
AnupRaj
  • 661
  • 5
  • 11
0

This post already has been answered by many, but I feel its solution could be much simpler.

/* Hide scrollbar for Chrome, Safari and Opera */

.container::-webkit-scrollbar {
  display: none;
}

/* Hide scrollbar for Internet Explorer, Edge and Firefox */

.container {
    -ms-overflow-style: none;  /* Internet Explorer and Edge */
    scrollbar-width: none;  /* Firefox */
}

}

Note: The above method will just remove the visibility of the scrollbar, but it will still be functional. In case you want to remove scroll functionality, then you may use the below one:

container {
  overflow-y: hidden; /* Hide vertical scrollbar */
  overflow-x: hidden; /* Hide horizontal scrollbar */
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
pryansh
  • 197
  • 1
  • 8
-3

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • 23
    basically you are saying that width of the scroll bar on every screen with any resolution will be 2% – euvl Feb 16 '15 at 16:10