CSS
iOS
position fixed
web development
mobile browsers

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.

html
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
css
1:root {
2  --bottom-safe: env(safe-area-inset-bottom);
3}
4
5.page {
6  min-height: 100dvh;
7}
8
9.footer {
10  position: fixed;
11  left: 0;
12  right: 0;
13  bottom: 0;
14  padding: 12px 16px calc(12px + var(--bottom-safe));
15  background: #111827;
16  color: white;
17}

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.

css
1.header {
2  position: sticky;
3  top: 0;
4  z-index: 1000;
5  background: #0f172a;
6  color: white;
7}

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:

  • transform
  • filter
  • perspective
  • 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.

javascript
1const root = document.documentElement;
2
3function syncViewportHeight() {
4  const height = window.visualViewport ? window.visualViewport.height : window.innerHeight;
5  root.style.setProperty('--vvh', `${height}px`);
6}
7
8window.addEventListener('resize', syncViewportHeight);
9window.visualViewport?.addEventListener('resize', syncViewportHeight);
10syncViewportHeight();
css
.app-shell {
  min-height: var(--vvh);
}

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

Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No 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 course
Data 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.

Practice algorithms