Hiding body scrollbars using CSS

Let me start with a little disclaimer. Just because you can, doesn't mean you should use it. Hiding scrollbars can be bad for accessibility and user experience.

But there are rare cases where it makes sense, usually when you have scrolling effects or when modal is opened. So use it wisely.

Check the demo. And find the cross browser code below:

body {
  /* Firefox */
  scrollbar-width: none;
  /* IE 10+ */
  -ms-overflow-style: none;

/* WebKit - Safari, Chrome, Opera */
body::-webkit-scrollbar {
  width: 0;
  height: 0;

Don't forget you can style scrollbars in webkit based browsers. Also you can use this code on any other element, not just body. Happy coding.

Comments (1)

Petar Petrovic
04. Jun 2019, 08:44

I keep needing to toggle scrollbar on the body element while developing so I made a bookmarklet based on the CSS above. Thanks Stanko! The code is below in case others need it as well. Cheers!