Fixed cover sized background image with CSS which works on iOS and other mobile devices
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information. Fix broken links Oct 30, 2017
index-wrong.html Fix broken links Oct 30, 2017
index.html Fix broken links Oct 30, 2017

Making fixed cover sized background images work on mobile devices

In iOS a fixed cover background is handled using the whole document height instead of using only the viewport's height.


Example of an error: erroneous working

This will be stretched as big as the document's height, so the background image will displayed zoomed:

body {
      background: url( no-repeat center center fixed;
      -webkit-background-size: cover;
      -moz-background-size: cover;
      -o-background-size: cover;
      background-size: cover;


Solution: fixed with CSS

If you make the element itself (body:after) fixed, this code works like a charm, by using only one CSS rule:

      position:fixed; /* stretch a fixed position to the whole screen */
      height:100vh; /* fix for mobile browser address bar appearing disappearing */
      z-index:-1; /* needed to keep in the background */
      background: url( center center;
      -webkit-background-size: cover;
      -moz-background-size: cover;
      -o-background-size: cover;
      background-size: cover;

Further info

More info: Stackoverflow: Background-image size cover not working on IOS

Live demo of the solution:,