How to hide scrollbar from any HTML element
Tags: html, beginners, tutorial, webdev
Published: 2020-02-05 19:38:38

---
title: How to hide scrollbar from any HTML element
cover_image: https://res.cloudinary.com/ashwamegh/image/upload/v1580931415/use-css-to-hide--scrollbar_lh3hcn.png
published: true
description: This is a short article about hiding the scrollbar from HTML elements.
tags: HTML, beginners, tutorial, webdev
---

# Use CSS to hide the scrollbar


There are times when we need to hide the scrollbar from the HTMl elements. The uses can vary from person to person. It is *opinionated* topic to keep the scrollbar or not based on __User Interactions(UI)/User Experience(UX)__.

Most of the time, I don't like to show the scrollbar to the user because of design practices I follow.

To achieve this, you just need to tickle with CSS to add some __pseudo selectors__ for hiding it based on Browser's stylings

Let's see the default UI for scroll elements which will show the scrollbar.

We will declare a `div` which will contain a list of items and then we will apply some CSS to provide `max-width` and `max-height` to see the scroll behaviour.

```html
<!-- Element that contains scrollbar -->
<div class="scroll-show">
    <ul>
      <li>Some Value</li>
      <li>Some Value</li>
      <li>Some Value</li>
      <li>Some Value</li>
      <li>Some Value</li>
      <li>Some Value</li>
      <li>Some Value</li>
      <li>Some Value</li>
      <li>Some Value</li>
      <li>Some Value</li>
      <li>Some Value</li>
      <li>Some Value</li>
      <li>Some Value</li>
      <li>Some Value</li>
      <li>Some Value</li>
      <li>Some Value</li>
      <li>Some Value</li>
    </ul>
  </div>
```

```css
.scroll-show ul {
  max-height: 100px;
  max-width: 200px;
  overflow: auto;
  border: 2px solid #f3f3f3;
  padding-left: 16px;
}
```

Let's see how it look in the screen

{% jsfiddle https://jsfiddle.net/shashank7200/xbk8sdto result,html,css %}


You see, browser automatically adds the scrollbar by default, but If we want to hide, we can do it.

Now, we will add some css to the element to hide the scrollbar:


We will declare a `div` with some other class name which will contain same number of items and then we will use the same CSS but with some extra rules to see the scroll behaviour but not see the scrollbar.

```html
<!-- Element that contains scrollbar -->
<div class="scroll-hide">
  <ul>
    <li>Some Value</li>
    <li>Some Value</li>
    <li>Some Value</li>
    <li>Some Value</li>
    <li>Some Value</li>
    <li>Some Value</li>
    <li>Some Value</li>
    <li>Some Value</li>
    <li>Some Value</li>
    <li>Some Value</li>
    <li>Some Value</li>
    <li>Some Value</li>
    <li>Some Value</li>
    <li>Some Value</li>
    <li>Some Value</li>
    <li>Some Value</li>
    <li>Some Value</li>
  </ul>
</div>
```

```css
.scroll-hide ul {
  max-height: 100px;
  max-width: 200px;
  border: 2px solid #f3f3f3;
  padding-left: 16px;
  overflow: auto;
  /* this will hide the scrollbar in mozilla based browsers */
  overflow: -moz-scrollbars-none;
  scrollbar-width: none;
  /* this will hide the scrollbar in internet explorers */
  -ms-overflow-style: none;
}

/* this will hide the scrollbar in webkit based browsers - safari, chrome, etc */
.scroll-hide ul::-webkit-scrollbar { 
  width: 0 !important;
  display: none; 
}
```

Let's see, whether we achieved what we wanted or not

{% jsfiddle https://jsfiddle.net/shashank7200/2v6aunq1 result,html,css %}


Here, you can see that, the scrollbar is no longer can be seen, but the functionality for scrolling remain intact.

Hope this helps you someway. Do comment your thoughts on anything, you would like to change or add.