DEV Community

Prevent history navigation on horizontally-scrolling elements with CSS

Dan Burzo on October 16, 2019

Behold a horizontally-scrolling element: .reel { display: flex; overflow-x: scroll; } Enter fullscreen mode Exit fullscree...
Collapse
 
simevidas profile image
Šime Vidas

Is there a demo? This CSS property doesn’t seem to be supported in Safari.

Collapse
 
danburzo profile image
Dan Burzo

The property is only supported on Chrome, Firefox and Edge. I'll whip up a demo that shows the behavior.

Collapse
 
danburzo profile image
Dan Burzo

I've updated the article with a link to the demo. Hope it helps!

Collapse
 
simevidas profile image
Šime Vidas

A two-finger swipe to the right triggers the browser Back action, while two fingers to the left triggers the Forward action.

Is this a standard feature on Windows laptops?

Thread Thread
 
danburzo profile image
Dan Burzo

I have tested on a Microsoft Surface machine running Windows 10 and the gesture is enabled in Edge and Chrome (Firefox does not support it currently). I think the hardware needs to have a Precision Touchpad for this to work.

Thread Thread
 
simevidas profile image
Šime Vidas

Thanks for checking. I tried on a regular Windows laptop, and there were no such gestures, at least not by default.

I also tried on my two Android phones, and swiping from the edges did not navigate in the browser for me. However, it seems to be an optional feature, according to Jason Miller, but I couldn’t find it.

Thread Thread
 
danburzo profile image
Dan Burzo

Interesting! In either case, I would not expect overscroll-behavior to affect mobile navigation gestures, since they are separate from scrolling gestures, and much less likely to be performed accidentally.

Collapse
 
mynameisbxh profile image
mynameisbxh

This CSS property doesn’t seem to be supported in Chrome 97.0.4692.71.

Collapse
 
danburzo profile image
Dan Burzo

What operating system are you on? I don't have Chrome 97 specifically, but it works fine in Chrome 98 and 99 on macOS.

Collapse
 
kostia1st profile image
Kostiantyn Kolesnichenko

Windows 11, Chrome 128

overscroll-behavior-x: none has no BACK-gesture prevention when scrolling the container horizontally via touchpad with two fingers. It still triggers BACK.

Collapse
 
websmyth profile image
Dave Smyth

Brilliant tip: thank you!

Collapse
 
danburzo profile image
Dan Burzo

Thanks, Dave! Hope it's useful :-)

Collapse
 
vovchisko profile image
Vladimir Ishenko

Damn handy article for today :3
Thanks, Dan!

Collapse
 
matheusmurden profile image
Matheus Murden

Very Very useful! Easy to implement and has a noticeable impact in the perceived smoothness