> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# Safe area

Keep content clear of the notch, the status bar and the home indicator. Lynx reads the same `env(safe-area-inset-*)` values that iOS Safari does.

The **safe area** is the part of the screen that hardware and system bars don't cover. On a recent iPhone:

- The notch or Dynamic Island covers the top edge.
- The **home indicator** (the bar you swipe up) covers the bottom.

On the web, a page with `viewport-fit=cover` pads itself with `env(safe-area-inset-top)` and its siblings. Lynx supports the same four values.

## Pad with `env()`

```css
.screen {
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

.tab-bar {
  /* a 56px bar, plus room for the home indicator */
  height: calc(56px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
}
```

- **There are four values:** `safe-area-inset-top`, `safe-area-inset-right`, `safe-area-inset-bottom` and `safe-area-inset-left`.
- **They work inside `calc()`**, as in `.tab-bar` above.
- **Where no inset is known, the value is 0.** The padding collapses instead of breaking the layout.

## Where the insets come from

| Where the app runs                                          | What `env()` gives                                                                                      |
| ----------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| Apps from `ng build --platform`                             | The window's insets, on iOS and Android, following rotation. 0 on every side with `"edgeToEdge": false` |
| [Lynx Explorer](/guide/glossary.md#lynx-explorer) on iPhone | The window's insets, wherever your page sits on screen                                                  |
| Your own iOS app                                            | The window's insets when the LynxView was created, or the insets your app sends (see below)             |
| Your own Android app                                        | 0 on every side, unless your app sends the insets (see below): Lynx doesn't read them on Android        |
| [Web preview](/guide/glossary.md#web-preview)               | 0                                                                                                       |

### The apps `ng build --platform` makes

They draw the page **edge to edge**: over the whole screen, under the status bar and the home indicator. Safari does the same for a page with `viewport-fit=cover`.

- A scroll view's content scrolls under the status bar.
- A header image or a map reaches the top edge.
- A bar that floats at the bottom, such as the [dock](/dolan/dock.md), floats over a page that runs to the bottom of the screen.

Pad the content, not the screen:

```angular-html
<scroll-view scroll-orientation="vertical" class="flex-1">
  <view class="flex flex-col px-4 pt-safe-3 pb-safe-24">
    <!-- the first row starts below the status bar, and scrolls under it -->
  </view>
</scroll-view>
```

- **Overlays cover the whole screen too.** An [`<overlay>`](/api/elements/overlay.md), and so a [bottom sheet](/dolan/bottom-sheet.md) or a dialog, reaches the bottom edge. Pad its content too, as the bottom sheet does with `pb-safe`.
- **`env()` follows the insets when they change:** when the phone rotates, and on Android when the keyboard opens.
- **The Android keyboard pushes the page up**, so the input you type into stays above it. The bottom inset is 0 while it's open, because the page then ends above the navigation bar.

The apps send the insets as numbers too, with `isNotchScreen` and `edgeToEdge`: see [What the generated apps pass](/guide/embedding/host-data.md#what-the-generated-apps-pass).

:::warning Don't define a CSS variable with `env()`

In a stylesheet, `--gap: calc(env(safe-area-inset-top) + 8px)` keeps Lynx's own `env()`, which is 0 in these apps. Write `env()` where the variable is read instead:

```css
padding-top: calc(env(safe-area-inset-top) + 8px);
```

:::

Why: Lynx's own `env()` can't follow the window. On Android it's always 0, and on iOS each element reads it once.

So the build points each `env(safe-area-inset-*)` in a stylesheet at a CSS variable the page sets from the app's insets. The runtime writes the insets into inline styles and style bindings itself. A CSS variable defined in a stylesheet is the one place neither reaches.

#### Turn edge to edge off

To keep the page inside the safe area instead, set `edgeToEdge` to `false` in the build target's options in `angular.json`:

```jsonc title="angular.json"
"options": {
  "appName": "Example",
  "appId": "com.example.app",
  "edgeToEdge": false
}
```

The page then starts below the status bar and ends above the home indicator, and `env()` is 0 on every side.

### Your own app

On iOS, Lynx reads the window's insets each time a [LynxView](/guide/glossary.md#lynxview) is created, and never again:

- A LynxView created before its window is shown reads 0.
- One on screen keeps the insets it read, even when the phone rotates.

To have `env()` follow the window as the generated apps do, send the same global props they send. This works on Android too.

- `edgeToEdge: true`
- `safeAreaTop`, `safeAreaRight`, `safeAreaBottom` and `safeAreaLeft`: the part of the LynxView the system bars cover

Send them again whenever they change.

## Tailwind utilities

The [UI components](/dolan/index.md)' theme adds padding utilities built on `env()`:

- **Tailwind 4:** its `tailwind.css`.
- **Tailwind 3:** its Tailwind plugin, `blotchPlugin`.

`npx @blotch/dolan init` copies the one your app needs into your project.

```angular-html
<!-- padding equal to the inset -->
<view class="pb-safe">...</view>

<!-- 1rem of padding plus the inset: calc(1rem + env(safe-area-inset-bottom)) -->
<view class="pb-safe-4">...</view>
```

| Class                                   | Padding                          |
| --------------------------------------- | -------------------------------- |
| `pt-safe` `pr-safe` `pb-safe` `pl-safe` | The inset on one side            |
| `px-safe` `py-safe`                     | The insets on two opposite sides |
| `p-safe`                                | The insets on all four sides     |
| `pt-safe-<n>` `pb-safe-<n>` and so on   | A spacing value plus the inset   |

The `<n>` takes any value from your spacing scale, as `p-<n>` does: `pb-safe-8`, `pt-safe-2`.

## Check for a notch in TypeScript

Prefer CSS: `env()` adapts to every device without code. For logic CSS can't express, inject `LynxSafeArea`.

```typescript title="src/app/header.ts"
import { Component, inject } from '@angular/core';
import { LYNX_ELEMENTS, LynxSafeArea } from '@blotch/angular-lynx';

@Component({
  selector: 'app-header',
  imports: [LYNX_ELEMENTS],
  template: `
    <view
      class="app-header"
      [class.app-header-notch]="safeArea.isNotchScreen()"
    >
      <text>Inbox</text>
    </view>
  `,
  styles: `
    .app-header {
      padding: 12px 16px;
    }
    .app-header-notch {
      padding-top: calc(12px + env(safe-area-inset-top));
    }
  `,
})
export class Header {
  protected readonly safeArea = inject(LynxSafeArea);
}
```

- **`isNotchScreen()`** is a signal that's `true` when the device has a notch or camera cutout. It comes from the [host app](/guide/glossary.md#host-app) (the native app that runs your bundle). Lynx Explorer and the apps that `ng build --platform` makes pass it.
- **`platform`** is the operating system. On phones it's `'iOS'`, `'Android'` or `'Harmony'`, which is Huawei's HarmonyOS.
- **`SAFE_AREA_INSET_TOP`**, `SAFE_AREA_INSET_RIGHT`, `SAFE_AREA_INSET_BOTTOM` and `SAFE_AREA_INSET_LEFT` are the `env()` strings, such as `'env(safe-area-inset-top)'`, for building styles in TypeScript.

## Related

- [`LynxSafeArea` API](/api/angular-lynx/device/safe-area.md)
- [Run on iOS and Android](/guide/native-apps.md)
- [Theming the UI components](/dolan/theming.md)
- [CSS on Lynx](/guide/styling/index.md)
