Skip to main content

Explore your training options in 10 minutes

How to Use CSS to Hide Scrollbars

Christina Kopecky - December 29, 2020

Scrollbars and User Experience

Users are now accustomed to a certain experience when navigation websites. For example, you would expect the logo of a business in the upper left corner of a site to take you to the homepage. But what if it doesn’t? What if everything on that site did the opposite of what you thought it would do?

Just imagine if a scrollbar existed, but as you moved your scroll button on your mouse or you dragged your fingers on the trackpad of your device, nothing happened . That would be considered a horrible user experience .

What makes or breaks a good user experience can be a post on its own, but part of it is most definitely properly functioning scrollbars and the ability to hide them for aesthetics.

Get offers and scholarships from top coding schools illustration

Find Your Bootcamp Match

  • Career Karma matches you with top tech bootcamps
  • Access exclusive scholarships and prep courses

By continuing you agree to our Terms of Service and Privacy Policy , and you consent to receive offers and opportunities from Career Karma by telephone, text message, and email.

Scrollbars are very good indicators of what we can expect to see on a webpage. If we see a scrollbar, we expect the need to scroll down to view content. When we don’t see a scrollbar, usually it’s for one of two reasons:

  1. What you see is what you get – the height and width of your viewport (your screen) matches the height and width of the site.
  2. The design of the site incorporates some sort of animated arrow or feature that indicates there is more content available via scrolling. Only when we start to scroll will the scroll bar appear. It’s default is to stay hidden until then.

As developers, implementing decent scrollbar use will improve the user experience of a site, which in turn will keep clients on the site.

Side note: Be sure to use horizontal scroll bars when you intentionally want to use them. If they appear unintentionally on your site, it’s usually because something is off with the sizing of your components. Don’t hide horizontal scrollbars on purpose when they shouldn’t be there.

CSS Implementation

The very first thing to note about this implementation is that not all major browsers are created equal. What works for Firefox won’t work for Chrome or Internet Explorer and vice versa. CSS employs what we call vendor prefixes or browser prefixes to help us provide cross-browser support. We list them below:

Vendor Prefix Cheat Sheet

Vendor Prefix Browsers it covers
-webkit- Chrome, Safari, new versions of Opera and most iOS browsers, including Firefox for iOS
-moz- Firefox (not iOS)
-o- Old versions of Opera
-ms- Internet Explorer and MS Edge

URL: Credit: MDN – CSS Prefixes

Alt Text: Mozilla Developer Network has created a handy cheat sheet for remembering which prefix to use

Caption: MDN has created a handy cheat sheet for remembering which prefix to use for which browser

The question then becomes, how do we know when we need prefixes and when we don’t? Those who create CSS are always experimenting with new properties and new ways of doing things – if there is a property that is fairly new, odds are it’s not compatible across all browsers yet.

Thankfully, there are tools available that will take a look at your CSS and add the prefixes you need. You can also do it manually and use a site like caniuse or the MDN docs to help you determine browser compatibility.

Venus, a software engineer at Rockbot

"Career Karma entered my life when I needed it most and quickly helped me match with a bootcamp. Two months after graduating, I found my dream job that aligned with my values and goals in life!"

Venus, Software Engineer at Rockbot

Let’s Code!

<!DOCTYPE html>
       <title>CSS: Hide the Scrollbar</title>
           * {
               box-sizing: border-box;
               scrollbar-width: none; /* Firefox implementation */
           body {
               max-height: 500px;
           h1 {
               text-align: center;
           .container, .sample-text {
               max-height: 500px;
               height: 500px;
           .container {
               width: 450px;
               border: 2px solid #666666;
               background: lightgrey;
               overflow: scroll;
               min-height: 520px;
               margin: 0 auto;
           .inner-container {
               position: absolute;
               left: 10;
               overflow-x: hidden;
               overflow-y: scroll;
           .inner-container::-webkit-scrollbar {
               display: none; /* webkit browsers implementation */
           .sample-text {
               width: 425px;
               height: 475px;
               margin: 0px 0px 10px 10px;
   <!-- /* Sample Text From */ -->
       <h1>CSS Hide Scrollbar</h1>
       <div class="container">
           <div class="inner-container">
               <div class="sample-text">
                   <p>It is! It's the city of New New York! Strictly speaking,
                   it's the fifteenth New York since the original, so that
                   makes it
                   New York. River, you know my name. You whispered my name in
                   my ear! There's only one reason I would ever tell anyone my
                   name. There's only one time I could... New-new-Doctor. Don't
                   you think she looks tired? I'll tell you what, then:
                   don't...step on any butterflies. What have butterflies ever
                   done to you? Oh, yes. Harmless is just the word: that's why
                   I like it! Doesn't kill, doesn't wound, doesn't maim. But
                   I'll tell you what it does do: it is very good at opening
                   <p>Aw, I wanted to be ginger! I've never been ginger!
                   And you, Rose Tyler! Fat lot of good you were! You gave up
                   on me! Ooh, that's rude. Is that the sort of man I am now?
                   Am I rude? Rude and not ginger. Sweet, maybe... Passionate,
                   I suppose... But don't ever mistake that for nice. Please,
                   when Torchwood comes to write my complete history, don't
                   tell people I travelled through time and space with her
                   mother! New-new-Doctor. Don't you think she looks tired? I'm
                   the Doctor, I can save the world with a kettle and some
                   string! And look! I'm wearing a vegetable! New-new-Doctor.
                   I'm sorry. I'm so sorry. It is! It's the city of New New
                   York! Strictly speaking, it's the fifteenth New York since
                   the original, so that makes it
                   New York.</p>

When we run this code in Chrome, it should produce a grey div background and some text that you can scroll through. The two most common implementations are included – Firefox is toward the top of the code in the <style> tag. Most everything else is in the –webkit prefixed property.

What you’ll notice in your implementation is that there is no scroll bar, but it still has the functionality of a scroll bar. This is one way of several to hide your scrollbar in CSS. What else has worked for you? I challenge you to play with your code to see if you can find a different way.

About us: Career Karma is a platform designed to help job seekers find, research, and connect with job training programs to advance their careers. Learn about the CK publication.

What's Next?

Christina Kopecky

About the author: Christina is an experienced technical writer, covering topics as diverse as Java, SQL, Python, and web development. She earned her Master of Music in flute performance from the University of Kansas and a bachelor's degree in music with minors in French and mass communication from Southeast Missouri State. Prior to joining the Career Karma team in June 2020, Christina was a teaching assistant, team lead, and section lead at Lambda School, where she led student groups, performed code and project reviews, and debugged problems for students. Christina's technical content is featured frequently in publications like Codecademy,, and Educative.

Skip to main content