How to get the scroll bar with CSS overflow on iOS
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
Scrollable containers that work fine on desktop Safari or Chrome often behave differently on iPhone and iPad. On iOS, the main issue is not whether overflow works; it is that Safari prefers overlay scroll indicators and touch scrolling, so you cannot force a traditional always-visible scrollbar the way many desktop browsers allow.
What iOS Actually Supports
For a container to scroll on iOS Safari, it needs a constrained height or width and an overflow mode such as auto or scroll. In practice, vertical scrolling is the common case.
The key line for iOS is -webkit-overflow-scrolling: touch;. It enables momentum scrolling, which makes nested scroll areas feel native on touch devices.
Why the Scrollbar Seems Missing
On iOS, scroll indicators are typically transient. They appear while the user is actively scrolling and then fade out. That is normal platform behavior. CSS can make the element scrollable, but it cannot force iOS Safari to keep a classic scrollbar permanently painted.
So the right goal is usually:
- make the container actually scroll
- preserve smooth touch behavior
- provide enough visual cues that the area is scrollable
A subtle fade or clipped content edge often works better than fighting the platform.
Patterns That Work Better Than Forcing a Scrollbar
A common pattern is to combine overflow with a fixed height and a visible boundary.
The extra spacing at the end prevents the last line from feeling glued to the bottom edge. You can also show a heading such as “Scroll for more” above the panel if discoverability matters.
If the whole page already scrolls, nested scrollers can feel awkward. In that case, consider letting the page handle scrolling instead of creating a second scroll region.
A Practical Markup Pattern
In real layouts, the scrollable area is often inside a card or modal. Make the outer shell responsible for spacing and borders, and let the inner element handle overflow.
That separation avoids bugs where padding, border radius, and overflow compete with each other.
Limits of Scrollbar Styling on iOS
Developers sometimes try ::-webkit-scrollbar to style the scrollbar. That works in several desktop WebKit contexts, but support is limited and inconsistent on iOS Safari. Even where some styling appears, it is not a reliable way to guarantee a persistent visible track.
That means the best portable solution is structural CSS, not custom scrollbar painting.
Common Pitfalls
The first pitfall is setting overflow: auto without a fixed height. If the element can expand to fit its content, there is nothing to scroll.
Another common issue is forgetting -webkit-overflow-scrolling: touch, which makes the container feel less natural on iOS.
A third mistake is trying to force desktop-style scrollbar behavior on a mobile browser that intentionally hides indicators most of the time. Build around the native behavior instead.
Summary
- '
overflow-y: autoworks on iOS when the element has a constrained size.' - '
-webkit-overflow-scrolling: touchimproves nested scrolling behavior.' - iOS usually shows scroll indicators only while the user is scrolling.
- '
::-webkit-scrollbaris not a dependable solution for always-visible iOS scrollbars.' - Design the container so its scrollability is obvious even when the indicator is hidden.
Related reading
- How to Get the Title of a HTML Page Displayed in UIWebView?
- How to handle errors from setTimeout in JavaScript?
- How to handle promise when calling async JS method from C using Emscripten
- How to handle UnprocessedItems using AWS JavaScript SDK dynamoDB?
- How to get the selected index of a RadioGroup in Android
- How to get the selected index of a RadioGroup in Android
- How to have a processor intensive function update every tick of the metronome and draw to canvas using web workers?
- How to implement a Promise retry and undo
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.