# env()

> The `env()` CSS function inserts values defined by the browser, such as the safe-area insets around a device notch or rounded corners.

## How do I handle the iPhone notch with CSS env(safe-area-inset)?

The function that accesses environment variables, like safe area insets on mobile devices, to adjust the layout dynamically. It helps ensure that content doesn't overlap with system UI elements, like the notch or home bar, on devices with special hardware features.

- Topic: Global Functions
- Type: function
- Browser support: Chrome 69+, Chrome Android 69+, Edge 79+, Firefox 65+, Firefox Android 65+, Safari 11.1+, Safari iOS 11.3+

## Example

Wrong:

```css
.toolbar {
  position: fixed;
  bottom: 0;
  padding-bottom: 16px;
}
```

Right:

```css
.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 because `viewport-fit=cover` is missing.
- Writing `var(safe-area-inset-top)` instead of `env(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, like `env(safe-area-inset-bottom, 0px)`.
- Safe-area padding is added to existing padding with `max()` or `calc()`, 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`.

## Related cards

- [var()](https://wonderium.dev/css/var.md)
- [max()](https://wonderium.dev/css/max.md)
- [`<meta>`](https://wonderium.dev/html/meta.md)
- [Viewport Units](https://wonderium.dev/css/viewport-units.md)
- [PWA](https://wonderium.dev/web/pwa.md)

---

- Level: [CSS](https://wonderium.dev/css.md)
- HTML version: https://wonderium.dev/css/env
- Last updated: 2026-11-25
