env() CSS Function
The env() function inserts a value defined by the browser, such as safe-area-inset-top, the safe area around a phone's notch or rounded corners.
Description
The env() CSS function inserts the value of an environment variable defined by the browser. Environment variables are similar to custom properties, but they are global to the document and their values come from the device or browser rather than from your stylesheet. The best-known use is keeping content clear of the notch, rounded corners and home indicator on phones by using the safe area insets.
The first argument is the variable name. The safe area variables are safe-area-inset-top, safe-area-inset-right, safe-area-inset-bottom and safe-area-inset-left; for these to have a value on iOS you also need viewport-fit=cover in the page's viewport meta tag. Other variables include the titlebar-area-* values for installed web apps with window controls overlay, keyboard-inset-* for the on-screen keyboard, and viewport-segment-* for foldable devices. An optional second argument is a fallback value used when the variable is not defined. Unlike var(), env() can also be used in media queries.
/* Keep a fixed toolbar above the phone's home indicator */
.toolbar {
position: fixed;
bottom: 0;
left: 0;
right: 0;
padding-bottom: env(safe-area-inset-bottom, 0px);
}
/* Combine with calc() for extra spacing */
header {
padding-top: calc(env(safe-area-inset-top, 0px) + 1rem);
}
Syntax
env() = env( <custom-ident> <integer [0,∞]>*, <declaration-value>? )
Values
- <custom-ident>The name of the environment variable, such as safe-area-inset-top, safe-area-inset-bottom, titlebar-area-height, keyboard-inset-height or viewport-segment-width. Names are case-sensitive.
- <integer>Optional. Indices for variables that have several values, such as the viewport-segment-* variables on foldable devices.
- <declaration-value>Optional. A fallback value used if the environment variable is not available.
Example
Browser Support
The following information will show you the current browser support for the CSS env() function. Hover over a browser icon to see the version that first introduced support for this CSS function.
Desktop





Tablets & Mobile





