env()
Example
.toolbar {
position: fixed;
bottom: 0;
padding-bottom: 16px;
}.toolbar {
position: fixed;
bottom: 0;
padding-bottom: max(16px, env(safe-area-inset-bottom));
}max() keeps the normal padding and grows it on devices with a home indicator, so buttons stay tappable.
Common mistakes
env(safe-area-inset-bottom)is always 0 becauseviewport-fit=coveris missing.- Writing
var(safe-area-inset-top)instead ofenv(safe-area-inset-top).
Key points
- The viewport meta tag includes
viewport-fit=cover, otherwise safe-area insets are zero. env()calls include a fallback, likeenv(safe-area-inset-bottom, 0px).- Safe-area padding is added to existing padding with
max()orcalc(), not replacing it.
Interview questions
What is the difference between env() and var()?
var() reads custom properties you define. env() reads values the browser provides, like safe-area insets.
Why is env(safe-area-inset-top) zero?
Usually the viewport meta tag lacks viewport-fit=cover, or the device has no notch or rounded corners.
Which safe-area values can env() read?
safe-area-inset-top, safe-area-inset-right, safe-area-inset-bottom and safe-area-inset-left.