Favorites

env() CSS Function

env()
CSS FunctionThis function is supported by all modern browsers.
Updated 21st November 2026

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.

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee

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

<div class="wrap">
<h1>CSS env() examples</h1>
<div class="phone">
<div class="header">Header</div>
<div class="body">The header and bottom bar use env(safe-area-inset-*) so they stay clear of a phone's notch and home indicator. Open this page on a phone with viewport-fit=cover to see real values.</div>
<div class="bar">Bottom bar</div>
</div>
</div>
/* Base demo layout */
* { box-sizing: border-box; }

body {
margin: 24px;
font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
background: #f5f7fb;
color: #102a43;
}

.wrap {
max-width: 860px;
margin: 0 auto;
}

h1 {
font-size: 20px;
margin: 0 0 16px;
}

.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 16px;
}

.card {
background: #fff;
border-radius: 12px;
padding: 16px;
box-shadow: 0 6px 18px rgba(16, 42, 67, 0.08);
}

.label {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
font-size: 12px;
color: #486581;
margin-top: 10px;
word-break: break-word;
}

.note {
font-size: 13px;
color: #486581;
margin-top: 14px;
}

/* env() examples */
.phone {
position: relative;
max-width: 300px;
height: 320px;
margin: 0 auto;
border-radius: 28px;
border: 8px solid #0f172a;
background: #fff;
overflow: hidden;
}

.header,
.bar {
position: absolute;
left: 0;
right: 0;
background: #2563eb;
color: #fff;
font-weight: 600;
text-align: center;
}

/* safe-area values are 0 on most desktops, so the fallbacks add visible padding */
.header {
top: 0;
padding: calc(env(safe-area-inset-top, 12px) + 8px) 12px 12px;
}

.bar {
bottom: 0;
padding: 12px 12px calc(env(safe-area-inset-bottom, 16px) + 8px);
}

.body {
padding: 80px 16px;
font-size: 14px;
line-height: 1.5;
}
Open in editor

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.

This function is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee