DEV Community

Cover image for How to hide scrollbar on your element in Tailwind
Derick Zihalirwa
Derick Zihalirwa

Posted on • Updated on

How to hide scrollbar on your element in Tailwind

Hi there👋,

You don't want your UI to look like this?

Before

Here are two steps to follow in order to hide a scrollbar in your HTML elements using TailwindCss.

Step I

Go to your global.css file styles/global.css and past this code:

//global index.css
@tailwind base;
@tailwind components;
@tailwind utilities;

// add the code bellow
@layer utilities {
      /* Hide scrollbar for Chrome, Safari and Opera */
      .no-scrollbar::-webkit-scrollbar {
          display: none;
      }
     /* Hide scrollbar for IE, Edge and Firefox */
      .no-scrollbar {
          -ms-overflow-style: none;  /* IE and Edge */
          scrollbar-width: none;  /* Firefox */
    }
  }
Enter fullscreen mode Exit fullscreen mode

At this point we added ::-webkit-scrollbar to target the scrollbar style in Chrome,Safari, Edge and Opera.

no-scrollbar is the class that we are going to use for hidding the scrollbar.

Step II

Now use no-scrollbar to hide the scrollbar in your elements. Like this:

<div className="w-full h-42 overflow-y-scroll no-scrollbar">...</div>
Enter fullscreen mode Exit fullscreen mode

Result

After

I hope you find this post useful.

Feel free to connect with me on Twitter

Top comments (23)

Collapse
 
collinsedim profile image
Collins Edim • Edited

Great share, Derick. This really helped me 🫡

BTW, if you're using TailwindCSS v3.0 or higher, you should remove:

@variants responsive {
}
Enter fullscreen mode Exit fullscreen mode

else you'll get this warning in terminal:

warn - The `@variants` directive has been deprecated in Tailwind CSS v3.0.
warn - Use `@layer utilities` or `@layer components` instead.
warn - https://tailwindcss.com/docs/upgrade-guide#replace-variants-with-layer
Enter fullscreen mode Exit fullscreen mode
Collapse
 
derick1530 profile image
Derick Zihalirwa

I've already updated the code based on your suggestion, Nice Catch

Collapse
 
huyong007 profile image
胡永

you win chatgpt4 for this problem

Collapse
 
derick1530 profile image
Derick Zihalirwa • Edited

Thank you so much for your kind words!

Collapse
 
xbdirisxk profile image
Abdirisakhd

thanks this help me alot

Collapse
 
derick1530 profile image
Derick Zihalirwa

Your are welcome

Collapse
 
zeeshansafdar48 profile image
Zeeshan Safdar

Amazing Derick. You solved my problem.

Collapse
 
amsalegebrehana profile image
Amsale Gebrehana

Great! Thank you.

Collapse
 
adamthedeveloper profile image
Adam

thank you!

Collapse
 
derick1530 profile image
Derick Zihalirwa • Edited

I'm glad it helped

Collapse
 
francois18 profile image
Francois18

Nice👏🎉

Collapse
 
derick1530 profile image
Derick Zihalirwa

Thank you

Collapse
 
paras231 profile image
paras231

Thanks this helped

Collapse
 
derick1530 profile image
Derick Zihalirwa

Glad it helped

Collapse
 
ashalda profile image
Alex Shalda

Awesome!!!!

Collapse
 
visweswar39 profile image
Visweswar

Thanks mate..!

Collapse
 
angelmtr profile image
Mosi

Thank You <3

Collapse
 
derick1530 profile image
Derick Zihalirwa

you are welcome mate

Collapse
 
rmscoal_84 profile image
Rifky Manuel Satyana

Awesomeeee. Helped me a lot. Thanks!

Collapse
 
derick1530 profile image
Derick Zihalirwa

Glad it helped ✅

Collapse
 
hevpro profile image
Hector Esquerdo Valverde

Thanks! Super cool!

Collapse
 
mustafadede profile image
Mustafa DEDE

Thank you!

Collapse
 
derick1530 profile image
Derick Zihalirwa

You re welcome mate, glad it helped!

Some comments have been hidden by the post's author - find out more