# Hide Scrollbar in CSS (and Style a Custom Scrollbar)

> Hide the scrollbar with CSS while keeping scrolling, hide it completely, hide only the horizontal one, prevent layout shift with scrollbar-gutter, and style a custom scrollbar in every browser.

Author: [Marko Denic](https://markodenic.com/) | Published: 2026-10-19 | Updated: 2026-10-19 | Topics: CSS, Tutorial, Web Development | Canonical: https://markodenic.com/hide-scrollbar-css/

![Hide Scrollbar in CSS (and Style a Custom Scrollbar)](https://markodenic.com/wp-content/uploads/2026/10/og-hide-scrollbar-css.png)

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

```css
.no-scrollbar {
  overflow: auto;
  scrollbar-width: none;          /* all modern browsers */
}

.no-scrollbar::-webkit-scrollbar {
  display: none;                  /* older Chrome and Safari */
}
```

### Demo:

```html
<div class="sb-demo">
  <div class="sb-demo__row">
    <span>Swipe</span><span>or</span><span>scroll</span><span>sideways</span><span>no</span><span>scrollbar</span><span>here</span>
  </div>
  <div class="sb-demo__box">
    <p>This box has a custom thin scrollbar.</p>
    <p>Scroll down to see it.</p>
    <p>The thumb is blue and the track is light.</p>
    <p>It uses the standard scrollbar-color and scrollbar-width properties.</p>
    <p>That's it.</p>
  </div>
</div>
```

```css
.sb-demo {
  display: grid;
  gap: 16px;
  padding: 16px;
  border-radius: 16px;
  background: #f1f5f9;
  font: 16px/1.5 system-ui, sans-serif;
  color: #0f172a;
}

/* 1. Horizontal scroller, scrollbar hidden */
.sb-demo__row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
}

.sb-demo__row::-webkit-scrollbar {
  display: none;
}

.sb-demo__row span {
  flex: 0 0 auto;
  padding: 16px 24px;
  border-radius: 10px;
  background: #1d4ed8;
  color: #fff;
  font-weight: 600;
}

/* 2. Custom scrollbar */
.sb-demo__box {
  height: 120px;
  overflow-y: auto;
  padding: 0 16px;
  border-radius: 10px;
  background: #fff;
  scrollbar-width: thin;
  scrollbar-color: #3b82f6 #e2e8f0; /* thumb track */
}
```

[See the live demo](https://markodenic.com/hide-scrollbar-css/#demo)

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.

```css
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.

```css
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.

```css
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.

```css
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.

```css
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](https://markodenic.com/css-tips/#css-custom-scrollbar).

```css
.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](https://markodenic.com/css-tips/#css-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.

Related: [CSS tips you won’t see in most tutorials](https://markodenic.com/css-tips/), [CSS Flexbox](https://markodenic.com/css-flexbox/), [CSS Grid](https://markodenic.com/css-grid/) and [CSS ::before and ::after](https://markodenic.com/css-before-after/).
