103

I have this element called items and the content inside the element is longer than the element height, I want to make it scrollable but hide the scroll bar, how would I do that?

<div class="left-side">
    <div
      class="items"
      style="display:block;width: 94%;margin: 0 auto;overflow: hidden;"
    >
    </div>
</div>
.left-side {
    height: 878px;
    padding-top: 20px;
    width: 1470px;
}

I tried setting the left-side class overflow to auto, but that didn't do anything.

4

10 Answers 10

190

You can hide it:

html {
  overflow:   scroll;
}

::-webkit-scrollbar {
    width: 0px;
    background: transparent; /* make scrollbar transparent */
}

For further information, see: Hide scroll bar, but while still being able to scroll

9
  • 3
    you could hide it, but it would be very poor usability. Commented Apr 3, 2017 at 13:46
  • 3
    Even in the provided link it states this doesn't work in FF or IE
    – DasBeasto
    Commented Dec 18, 2017 at 18:07
  • 4
    This only works on desktop chrome. It doesn't work on any other browser I've tested on.
    – whaley
    Commented Dec 27, 2018 at 22:21
  • 4
    why is background: transparent; needed? Wouldn't width: 0 be enough?
    – adam.k
    Commented Oct 24, 2019 at 10:32
  • 2
    for horizontal scrollbar, it's pretty obvious but we'd set height: 0;
    – Masroor
    Commented Dec 7, 2020 at 8:47
92

I combined a couple of different answers in SO into the following snippet, which should work on all, if not most, modern browsers I believe. All you have to do is add the CSS class .disable-scrollbars onto the element you wish to apply this to.

.disable-scrollbars::-webkit-scrollbar {
  background: transparent; /* Chrome/Safari/Webkit */
  width: 0px;
}
    
.disable-scrollbars {
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none;  /* IE 10+ */
}

And if you want to use SCSS/SASS:

.disable-scrollbars {
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none;  /* IE 10+ */

  &::-webkit-scrollbar {
    background: transparent; /* Chrome/Safari/Webkit */
    width: 0px;
  }
}
2
  • 3
    To have this rule apply to all children, .disable-scrollbars * { and .disable-scrollbars *::-webkit-scrollbar {
    – Meredith
    Commented May 15, 2019 at 10:31
  • add height: 0; next to width to also catch horizontal scrollbars Commented May 9, 2023 at 23:55
13

Hope this helps

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

/* Hide scrollbar for IE, Edge and Firefox */
html {
  -ms-overflow-style: none;  /* IE and Edge */
  scrollbar-width: none;  /* Firefox */
}
9

Similar to Kiloumap L'artélon's answer,

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

works too

3
  • 4
    This only works on desktop chrome. It doesn't work on any other browser I've tested on.
    – whaley
    Commented Dec 27, 2018 at 22:20
  • 2
    width: 0; seems to hide the horizontal scrollbar, but leaves a weird empty gap on Chrome desktop 83. display: none; does not have this issue. I threw in both just to be safe.
    – cyqsimon
    Commented Jun 29, 2020 at 8:21
  • This works well in Safari and Chromium, without adding any weird artifacts as the other suggestions do
    – Patronics
    Commented Feb 18 at 3:23
5

You can hide it on specific div usig class:

<div class="hide-scroll"></div>
.hide-scroll{
    overflow: scroll;
}

.hide-scroll::-webkit-scrollbar {
    background: transparent; /* make scrollbar transparent */
    width: 0px;
}
0
4

work on all major browsers

html {
    overflow: scroll;
    overflow-x: hidden;
}
::-webkit-scrollbar {
    width: 0px;  /* Remove scrollbar space */
    background: transparent;  /* Optional: just make scrollbar invisible */
}
1

You can make use of the SlimScroll plugin to make a div scrollable even if it is set to overflow: hidden;(i.e. scrollbar hidden).

You can also control touch scroll as well as the scroll speed using this plugin.

Hope this helps :)

1
  • 1
    This plugin doesn't even work on its own demo page, so it's unlikely to be a good solution...
    – charlesdeb
    Commented Jan 7, 2022 at 16:36
1

if you use sass, you can try this

&::-webkit-scrollbar { 
  width: 0px;
  background: transparent; /* make scrollbar transparent */
}
2
  • You haven't put any styles within this so this isn't going to do anything.
    – Sambuxc
    Commented Aug 4, 2022 at 12:39
  • Make sure that you put it on root, so it should work with html/body part.
    – Erik P_yan
    Commented Sep 2, 2022 at 5:50
1

Just add this to your css and the job is done...

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

/* Hide scrollbar for IE, Edge and Firefox */
body {
  overflow: -moz-scrollbars-none;
  -ms-overflow-style: none; /* IE and Edge */
  scrollbar-width: none; /* Firefox */
}
0

if you really want to get rid of the scrollbar, split the information up into two separate pages.

Usability guidelines on scrollbars by Jakob Nielsen:

There are five essential usability guidelines for scrolling and scrollbars:

  • Offer a scrollbar if an area has scrolling content. Don't rely on auto-scrolling or on dragging, which people might not notice.
  • Hide scrollbars if all content is visible. If people see a scrollbar, they assume there's additional content and will be frustrated if they can't scroll.
  • Comply with GUI standards and use scrollbars that look like scrollbars.
  • Avoid horizontal scrolling on Web pages and minimize it elsewhere.
  • Display all important information above the fold. Users often decide whether to stay or leave based on what they can see without scrolling. Plus they only allocate 20% of their attention below the fold.

To make your scrollbar only visible when it is needed (i.e. when there is content to scroll down to), use overflow: auto.

3
  • 4
    This is nice and sensible, but sometimes you really want to do things that sound strange without the context. For example, if you have a complex table component with one or more splitter, and the sections are scroll-synced, you only want the scrollbar on one section because it's obvious for the user that the whole thing is scrollable as one unit and individual scrollbars only add confusion. Commented Jan 21, 2019 at 17:30
  • 3
    This doesn't really answer the question
    – Kalimantan
    Commented Feb 26, 2019 at 19:58
  • 1
    You effectively told the OP that what he is trying to do is wrong. There are cases where it is right (a carousel is the most common one). In the case of a carousel, there is some other UI element that indicates the drag capability (arrows rendered by the application and/or position dots). Commented Apr 26, 2020 at 17:22

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.