Position fixed doesn't work on iPad and iPhone
Codemia Knowledge Hub ·
When position: fixed seems broken on iPhone or iPad, the CSS rule is usually fine. The problem is that iOS Safari changes the visible viewport during scroll, address-bar collapse, and keyboard display. Stable layouts come from better viewport sizing, safe-area handling, and avoiding patterns that break fixed-position anchoring.
Why fixed elements jump on iOS
On desktop browsers, a fixed header or footer stays attached to a predictable viewport. On iOS Safari, the visible viewport changes as browser chrome expands and collapses, so a layout built on assumptions like a static 100vh can jump or overlap content.
Typical symptoms:
- bottom bars shifting during scroll
- fixed headers overlapping content after URL bar changes
- controls moving unexpectedly when the keyboard opens
These are viewport-model problems, not proof that fixed positioning is unsupported.
Use dynamic viewport units and safe-area insets
Start by configuring the viewport and sizing the page with dynamic viewport units.
100dvh tracks the dynamic viewport more accurately than 100vh when the iOS browser UI changes height. Using 100vh everywhere and expecting it to match the visible viewport is the most common mistake here, followed by ignoring safe-area insets for bottom-fixed controls on devices with a home indicator.
Use sticky when fixed is more than you need
Some layouts use fixed positioning where position: sticky would do the job with fewer edge cases.
For a top bar that persists during page scroll, sticky is often more forgiving on mobile browsers. Use fixed only when the element must stay pinned to the viewport itself. Choosing the lighter behavior often solves the problem before any JavaScript is needed.
Check ancestors for transforms
A fixed element can misbehave if an ancestor creates a new containing or compositing context. The usual suspects:
transformfilterperspective- certain containment-related styles
If a fixed element acts as if it were absolutely positioned inside a wrapper, audit the ancestor chain before debugging the child. Removing an unnecessary transform on a layout wrapper often fixes it.
Handle keyboard resizing
The on-screen keyboard shrinks the visible viewport, which can make fixed elements jump or cover form fields. If fixed controls sit near inputs, you may need to react to viewport changes.
This is not always necessary, but on input-heavy mobile screens it makes the layout much more predictable.
Test on real devices
Desktop emulation is not enough for this class of bug, because iOS Safari's browser chrome and keyboard behavior are where it lives. At minimum, test:
- iPhone Safari with normal scrolling
- keyboard-open states on forms
- portrait and landscape
- iPad Safari if the layout targets tablets
Related reading
- Possible collisions in the standard JavaScript Object hash table implementation?
- pretty-print JSON using JavaScript
- prisma/client did not initialize yet. Please run prisma generate and try to import it again
- Programmatically fire button click event?
- Positioning MKMapView to show multiple annotations at once
- Possible to change where Android Virtual Devices are saved?
- Programmatically selecting text in an input field on iOS devices mobile Safari
- Promise is blocking the thread
System design interview problems on this topic
- Design Google Doc: solution and walkthrough
- Design Facebook Messenger: solution and walkthrough
- Design Typeahead Suggestion: solution and walkthrough
- Design an Online Presence Indicator Service: solution and walkthrough
.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 courseNo course covers this one yet
Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.
Build my courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.