brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: env(safe-area-inset-bottom) in CSS keeps buttons clear of the iPhone home bar

Css
~/tips/tip-css-safe-area-inset-notch

content="width=device-width, initial-scale=1, viewport-fit=cover">

A fixed bottom bar gets extra padding only on devices with a notch or home indicator.

A bottom bar fixed to the screen ends up under the home indicator on phones without a home button. CSS can ask the browser how much room that indicator takes.

<meta name="viewport"
  content="width=device-width, initial-scale=1, viewport-fit=cover">

.bottom-bar {
  position: fixed;
  inset: auto 0 0 0;
  padding: 1rem;
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
}

env() reads values that the browser provides. The four safe-area-inset-* values describe how far content must stay from each edge to avoid rounded corners, a notch or the home bar. With max() the bar gets at least 1rem of padding, and more when the device needs it.

The viewport tag matters. Only with viewport-fit=cover does the page extend into the unsafe areas, and only then are the insets more than zero. Without it, the browser keeps the page inside the safe area on its own and leaves the edges empty.

env() also takes a fallback, like env(safe-area-inset-bottom, 1rem), which is used when the variable does not exist at all. Support goes back years: Chrome 69, Firefox 65 and Safari 11.1. I’d test this in a phone simulator or on a real phone, since desktop browsers return zero.

Further reading: MDN: env()

More Css tips CSS Overview in Chrome DevTools audits the colors and fonts of a page .notice:empty { .toast { article { counter-reset: h2; } .toolbar { All Css tips (66) All topics

Link