
100vh in Safari on iOS
100vh in Safari on iOS êŽë š
Update 2021.07.08
There are new viewport units on the way that will finally solve this issue. 100dvh is the one youâre looking for.
When working with Viewport Units thereâs this longstanding and extremely annoying bug in Safari on iOS where it does not play nice with the vh unit. Setting a container to 100vh for example will actually result in an element thatâs a wee bit too tall: MobileSafari ignores parts of its UI when calculating 100vh.

Note
đ€ New to Viewport Units? Ahmad Shadeed has got you covered.
Apple/WebKitâs stance is that it works as intended, although itâs not what I (and many other developers) expect. As a result we have to rely on workarounds.
In the past Iâve used Viewport Units Buggyfill or Louis Hoebregtsâ CSS Custom Properties Hack to fix this behavior. I was glad to see that Matt Smith recently found a way to have MobileSafari render an element at 100vh using CSS:
As I replied on Twitter (bramus): Nice, but Iâd rather have MobileSafari fix the vh unit, as using -webkit-fill-available for this will only work to achieving 100vh.
If you want to achieve a perfect 50vh for example, using -webkit-fill-available wonât work as you canât use -webkit-fill-available in calc() (bramus). Above that it wonât work when the targeted element is nested somewhere deep in your DOM tree with one its parents already having a height set.
Come âon Safari, stop being the new IE6 âŠ
UPDATE 2020.05.16
Apparently this -webkit-fill-available workaround can negatively impact the Chrome browser:
Given this itâs recommended to selectively ship -webkit-fill-available to only Safari using a @supports rule that tests for -webkit-touch-callout support:
body {
height: 100vh;
}
@supports (-webkit-touch-callout: none) {
body {
height: -webkit-fill-available;
}
}
Alternatively you can still use Louis Hoebregtsâ CSS Custom Properties Hack, which uses JavaScript:
.my-element {
height: 100vh;
height: calc(var(--vh, 1vh) * 100);
}
const setVh = () => {
const vh = window.innerHeight * 0.01;
document.documentElement.style.setProperty('--vh', `${vh}px`);
};
window.addEventListener('load', setVh);
window.addEventListener('resize', setVh);