All Posts

How to hide scrollbars with Tailwind CSS

Scrollbars serve an important purpose – they let users know there is more content to explore. But sometimes, especially in modern web design, they just do not fit the aesthetic you are going for.
Test

Maybe you are building a sleek horizontal navigation, a custom image carousel, or a clean chat interface. Whatever the case, you want the scrolling functionality but not the visual clutter of scrollbars.

Good news: hiding scrollbars in Tailwind CSS is totally doable, and I will show you exactly how to do it the right way.

The browser compatibility challenge

Here is the thing about hiding scrollbars – different browsers need different approaches. Chrome and Safari use webkit-specific CSS properties, while Firefox has its own method, and older browsers like IE have their own quirks.

This means we need to write CSS that covers all these cases:

<div class='demo-container scrollbar-hide'>
  <p>This container has scrollable content but no visible scrollbar. Try scrolling with your mouse wheel or by dragging on mobile.</p>
  <p>More content here...</p>
  <p>And even more content to make it scroll...</p>
  <p>Keep scrolling to see more...</p>
  <p>Almost there...</p>
  <p>Last line of content!</p>
</div>

The CSS covers all major browsers, but now we need to integrate this with Tailwind CSS properly.

Creating a custom utility class

The cleanest approach is to add a custom utility class to your Tailwind setup. You can add this to your main CSS file using the @layer utilities directive:

<div class='max-w-md mx-auto space-y-4'>
  <div class='h-32 overflow-y-auto border border-gray-300 rounded-lg p-4 scrollbar-hide bg-gray-50'>
    <h3 class='font-semibold text-gray-800 mb-2'>Hidden Scrollbar</h3>
    <p class='text-gray-600 text-sm'>This content area is scrollable but the scrollbar is completely hidden. The user can still scroll with mouse wheel, trackpad, or touch gestures.</p>
    <p class='text-gray-600 text-sm mt-2'>More content to demonstrate scrolling behavior...</p>
    <p class='text-gray-600 text-sm mt-2'>Even more content here to make it scroll...</p>
    <p class='text-gray-600 text-sm mt-2'>And some final content at the bottom.</p>
  </div>

  <div class='h-32 overflow-y-auto border border-gray-300 rounded-lg p-4 bg-blue-50'>
    <h3 class='font-semibold text-gray-800 mb-2'>Regular Scrollbar</h3>
    <p class='text-gray-600 text-sm'>This is the same content but with the default scrollbar visible for comparison.</p>
    <p class='text-gray-600 text-sm mt-2'>More content to demonstrate scrolling behavior...</p>
    <p class='text-gray-600 text-sm mt-2'>Even more content here to make it scroll...</p>
    <p class='text-gray-600 text-sm mt-2'>And some final content at the bottom.</p>
  </div>
</div>
{{ slot:css }}
<style>
  @layer utilities {
  .scrollbar-hide {
    -ms-overflow-style: none;
    scrollbar-width: none;
  }
  .scrollbar-hide::-webkit-scrollbar {
    display: none;
  }
}
</style>
{{/slot:css}}

Now you can use scrollbar-hide alongside any of Tailwind's overflow utilities like overflow-auto, overflow-x-scroll, or overflow-y-auto.

Using Tailwind CSS v4 @utility directive

If you are using Tailwind CSS v4, there is an even cleaner way to define custom utilities using the new @utility directive:

<div class='grid grid-cols-1 md:grid-cols-2 gap-6 max-w-4xl mx-auto'>
  <div class='space-y-4'>
    <h3 class='text-lg font-semibold text-gray-800'>Horizontal Scroll (Hidden)</h3>
    <div class='w-full overflow-x-auto scrollbar-hide border border-gray-300 rounded-lg'>
      <div class='flex space-x-4 p-4 min-w-max'>
        <div class='w-24 h-24 bg-red-400 rounded-lg flex-shrink-0'></div>
        <div class='w-24 h-24 bg-blue-400 rounded-lg flex-shrink-0'></div>
        <div class='w-24 h-24 bg-green-400 rounded-lg flex-shrink-0'></div>
        <div class='w-24 h-24 bg-yellow-400 rounded-lg flex-shrink-0'></div>
        <div class='w-24 h-24 bg-purple-400 rounded-lg flex-shrink-0'></div>
        <div class='w-24 h-24 bg-pink-400 rounded-lg flex-shrink-0'></div>
      </div>
    </div>
  </div>

  <div class='space-y-4'>
    <h3 class='text-lg font-semibold text-gray-800'>Horizontal Scroll (Visible)</h3>
    <div class='w-full overflow-x-auto border border-gray-300 rounded-lg'>
      <div class='flex space-x-4 p-4 min-w-max'>
        <div class='w-24 h-24 bg-red-400 rounded-lg flex-shrink-0'></div>
        <div class='w-24 h-24 bg-blue-400 rounded-lg flex-shrink-0'></div>
        <div class='w-24 h-24 bg-green-400 rounded-lg flex-shrink-0'></div>
        <div class='w-24 h-24 bg-yellow-400 rounded-lg flex-shrink-0'></div>
        <div class='w-24 h-24 bg-purple-400 rounded-lg flex-shrink-0'></div>
        <div class='w-24 h-24 bg-pink-400 rounded-lg flex-shrink-0'></div>
      </div>
    </div>
  </div>
</div>

The v4 syntax is cleaner and uses nesting, which makes the code more readable. Plus, utilities created with @utility automatically work with all of Tailwind's variants like hover:, focus:, and responsive prefixes.

The webkit browser gotcha

Here is something important you need to know: in webkit browsers (Chrome, Safari, Opera), you cannot just override the scrollbar hiding to show it again. Once you hide it with ::-webkit-scrollbar { display: none; }, you cannot bring it back with another class.

So if you want responsive scrollbar visibility – like hidden on mobile but visible on desktop – you will need to be a bit creative:

<div class='max-w-lg mx-auto space-y-6'>
  <div class='bg-white rounded-lg shadow-md p-4'>
    <h3 class='font-semibold text-gray-800 mb-3'>Mobile-Only Hidden Scrollbar</h3>
    <div class='h-32 overflow-y-auto [@media(max-width:767px)]:scrollbar-hide border border-gray-200 rounded p-3'>
      <p class='text-sm text-gray-600 mb-2'>On mobile devices, this scrollbar is hidden for a cleaner look.</p>
      <p class='text-sm text-gray-600 mb-2'>On larger screens, the scrollbar is visible as usual.</p>
      <p class='text-sm text-gray-600 mb-2'>This gives you the best of both worlds.</p>
      <p class='text-sm text-gray-600 mb-2'>More content to make it scroll...</p>
      <p class='text-sm text-gray-600 mb-2'>Even more content here...</p>
      <p class='text-sm text-gray-600'>Final line of content.</p>
    </div>
  </div>
</div>

This uses Tailwind's arbitrary variant feature to apply the scrollbar hiding only on smaller screens, which works perfectly in webkit browsers.

Real-world examples where this shines

Let me show you some practical examples where hidden scrollbars really improve the user experience:

<div class='max-w-4xl mx-auto space-y-8'>
  <!-- Image gallery -->
  <div class='bg-white rounded-xl shadow-lg p-6'>
    <h3 class='text-lg font-semibold text-gray-800 mb-4'>Image Gallery</h3>
    <div class='flex space-x-4 overflow-x-auto scrollbar-hide pb-2'>
      <div class='w-48 h-32 bg-gradient-to-br from-purple-400 to-pink-400 flex-shrink-0 rounded-lg flex items-center justify-center text-white font-medium'>Image 1</div>
      <div class='w-48 h-32 bg-gradient-to-br from-blue-400 to-cyan-400 flex-shrink-0 rounded-lg flex items-center justify-center text-white font-medium'>Image 2</div>
      <div class='w-48 h-32 bg-gradient-to-br from-green-400 to-emerald-400 flex-shrink-0 rounded-lg flex items-center justify-center text-white font-medium'>Image 3</div>
      <div class='w-48 h-32 bg-gradient-to-br from-yellow-400 to-orange-400 flex-shrink-0 rounded-lg flex items-center justify-center text-white font-medium'>Image 4</div>
      <div class='w-48 h-32 bg-gradient-to-br from-red-400 to-pink-400 flex-shrink-0 rounded-lg flex items-center justify-center text-white font-medium'>Image 5</div>
    </div>
  </div>

  <!-- Navigation tabs -->
  <div class='bg-white rounded-xl shadow-lg p-6'>
    <h3 class='text-lg font-semibold text-gray-800 mb-4'>Horizontal Navigation</h3>
    <div class='flex space-x-1 overflow-x-auto scrollbar-hide'>
      <button class='px-4 py-2 bg-blue-500 text-white rounded-lg whitespace-nowrap'>Dashboard</button>
      <button class='px-4 py-2 bg-gray-200 text-gray-700 rounded-lg whitespace-nowrap hover:bg-gray-300'>Analytics</button>
      <button class='px-4 py-2 bg-gray-200 text-gray-700 rounded-lg whitespace-nowrap hover:bg-gray-300'>User Management</button>
      <button class='px-4 py-2 bg-gray-200 text-gray-700 rounded-lg whitespace-nowrap hover:bg-gray-300'>Settings</button>
      <button class='px-4 py-2 bg-gray-200 text-gray-700 rounded-lg whitespace-nowrap hover:bg-gray-300'>Billing</button>
      <button class='px-4 py-2 bg-gray-200 text-gray-700 rounded-lg whitespace-nowrap hover:bg-gray-300'>Support</button>
    </div>
  </div>
</div>

These examples show how hidden scrollbars create cleaner, more professional-looking interfaces. The functionality is still there – users can scroll horizontally through the gallery or navigation – but the visual clutter is gone.

Don't forget accessibility

While hidden scrollbars look great, you should always consider accessibility. Some users rely on visual cues like scrollbars to understand that content is scrollable. Here are a few things to keep in mind:

  • Add subtle visual hints like fade effects at the edges
  • Include touch/swipe indicators on mobile
  • Make sure keyboard navigation still works properly
  • Consider using scroll-behavior: smooth for better UX
<div class='max-w-2xl mx-auto bg-white rounded-xl shadow-lg p-6'>
  <h3 class='text-lg font-semibold text-gray-800 mb-4'>Product Showcase</h3>
  <div class='relative'>
    <div class='flex overflow-x-auto scrollbar-hide space-x-4 p-4'>
      <div class='w-32 h-32 bg-blue-400 rounded-lg flex-shrink-0 flex items-center justify-center text-white font-medium'>Product 1</div>
      <div class='w-32 h-32 bg-green-400 rounded-lg flex-shrink-0 flex items-center justify-center text-white font-medium'>Product 2</div>
      <div class='w-32 h-32 bg-purple-400 rounded-lg flex-shrink-0 flex items-center justify-center text-white font-medium'>Product 3</div>
      <div class='w-32 h-32 bg-red-400 rounded-lg flex-shrink-0 flex items-center justify-center text-white font-medium'>Product 4</div>
      <div class='w-32 h-32 bg-yellow-400 rounded-lg flex-shrink-0 flex items-center justify-center text-white font-medium'>Product 5</div>
    </div>

    <!-- Visual hint: fade gradient -->
    <div class='absolute right-0 top-0 bottom-0 w-12 bg-gradient-to-l from-white pointer-events-none rounded-r-xl'></div>

    <!-- Scroll indicator -->
    <div class='absolute bottom-2 right-2 text-xs text-gray-500 bg-white/80 px-2 py-1 rounded'>
      ← Scroll →
    </div>
  </div>
</div>

The fade effect and scroll indicator help users understand that there is more content to explore, even without the scrollbar.

That is how you hide scrollbars in Tailwind CSS! Whether you go with custom utilities, plugins, or Tailwind v4 new directive, you now have the tools to create clean, scrollable interfaces that do not compromise on functionality.

Remember to test across different browsers and always keep accessibility in mind. Your users will appreciate the cleaner look, and you will love how much more polished your interfaces appear.

Hope this helps you build better user experiences with Tailwind CSS!

Other posts you might like...

See more

Subscribe to our newsletter

Get notified when we add new templates, components, and more!

Thanks for subscribing!
Please check your email to confirm your subscription.

WindyBase Make development a breeze

WindyBase is a weekly curated Tailwind CSS template and tool directory built for the modern developer.

© 2026 WindyBase. All rights reserved.