I had trouble hiding the scrollbar on Safari (iPhone) and couldn’t find an answer, so here’s what worked for me.
What I’m Using:
- React v18
- iPhone 13 Mini (iOS 18.0.1)
- Safari (Version based on iOS 18.0.1, as of 02/02/2025)
The Solution:
- Target the
#root element:
In React apps, the main container is
usually a div with id="root". In your main CSS file, add:
#root {overflow: hidden;}
This disables scrolling on the root container and removes any scrollbars it might create,
Set up a scrollable container with hidden scrollbars:
Assign a custom class to the main container of the component that will be displayed on the screen (e.g., your Landing.js component).
.main-container { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.main-container::-webkit-scrollbar { display: none; }
This container handles the scrolling while keeping the scrollbar hidden.
Below is an example of my React tree:
<App>
<Routes>
<Route>
<Landing />
</Route>
</Routes>
</App>
Inside Landing.js:
Assign the .main-container class to the main div.
< div className="main-container">
< div className="inner-content">
{/* Your
content here. For example, I have a Hero section, About Us section, etc.. */}
</ div>
< /div>
Now, when the content height exceeds the screen height, it will scroll without showing the scrollbar.
I hope this helps anyone facing the same issue on Safari (iPhone)! If you're still stuck, reach out on IG @370zumaya.
Below is an example of my CSS code:
#root {
/* Manually hide scrollbars */
overflow: hidden;
}
.main-container {
overflow-y: auto;
}
.inner-content {
overflow-y: visible;
}
.main-container::-webkit-scrollbar {
display: none; /* Chrome, Safari, Edge */
}
overflow-y: hiddenso that the scrollbar stays inside that hidden overflow.