{"slug":"safe-area-handling-2","title":"safe-area-handling","summary":"Fixes notch, Dynamic Island, home indicator, display cutout, and system bar overlap in Capacitor apps. Covers `viewport-fit=cover` + `env(safe-area-inset-*)`, the Capacitor 8 SystemBars core plugin (`insetsHandling`, injected `--safe-area-inset-*` CSS variables for Android WebVie","platform":"Claude","tags":[],"authorName":"LLM Mart","authorSlug":"llm-mart","score":0,"source":"github","price":null,"verified":false,"createdAt":"2026-12-05T18:17:33.310211Z","repo":{"url":"https://github.com/Cap-go/capgo-skills","stars":79,"forks":4,"license":"MIT","updatedAt":"2026-12-05T16:44:30Z"},"bodyHtml":"<hr>\n<h2>name: safe-area-handling\ndescription: Fixes notch, Dynamic Island, home indicator, display cutout, and system bar overlap in Capacitor apps. Covers <code>viewport-fit=cover</code> + <code>env(safe-area-inset-*)</code>, the Capacitor 8 SystemBars core plugin (<code>insetsHandling</code>, injected <code>--safe-area-inset-*</code> CSS variables for Android WebView &lt; 140, removal of <code>android.adjustMarginsForEdgeToEdge</code>), Android 15/16 enforced edge-to-edge (<code>overlaysWebView</code> and <code>backgroundColor</code> of @capacitor/status-bar no longer work at targetSdk 36), iOS <code>contentInset</code>, and insets that change at runtime on rotation, iPad/foldable resizable windows. Use when headers sit under the status bar, tab bars hide behind the gesture bar, <code>env()</code> returns 0 on Android, or layout broke after upgrading to Capacitor 8 / targetSdk 35+. Do not use for keyboard overlap (capacitor-keyboard), Ionic/Konsta component theming (ionic-design, konsta-ui), Tailwind utility setup (tailwind-capacitor), or iOS multi-window/resizability adoption (capacitor-ios-resizability).</h2>\n<h1>Safe Area Handling in Capacitor</h1>\n<h2>When to Use</h2>\n<p>TRIGGER when:</p>\n<ul>\n<li>Content renders under the status bar, notch, Dynamic Island, cutout, home indicator, or Android navigation/gesture bar</li>\n<li><code>env(safe-area-inset-*)</code> is <code>0px</code> on Android, or correct only after rotation</li>\n<li>Layout broke after Capacitor 8 upgrade or raising <code>targetSdkVersion</code> to 35/36</li>\n<li><code>StatusBar.setOverlaysWebView</code> / <code>setBackgroundColor</code> stopped working on Android</li>\n<li>Landscape / split-screen / iPad windowed layouts have wrong side padding</li>\n</ul>\n<p>Do not use:</p>\n<ul>\n<li>Keyboard covering inputs: <code>capacitor-keyboard</code></li>\n<li>Ionic <code>ion-header</code>/<code>ion-toolbar</code> theming: <code>ionic-design</code>; Konsta <code>safeAreas</code>: <code>konsta-ui</code></li>\n<li>Tailwind plugin/utility setup: <code>tailwind-capacitor</code></li>\n<li>iOS scene sizing, <code>UIScreen.main</code>, multi-window: <code>capacitor-ios-resizability</code></li>\n<li>Splash screen colors: <code>capacitor-splash-screen</code></li>\n<li>Sticky hover, tap flash, input zoom, bounce, long-press callouts: <code>capacitor-native-feel</code></li>\n</ul>\n<h2>Facts that drive every decision</h2>\n<table>\n<thead>\n<tr>\n<th>Platform / version</th>\n<th>Behavior</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>iOS (all)</td>\n<td>WebView is full-screen. <code>env(safe-area-inset-*)</code> works only with <code>viewport-fit=cover</code>. <code>ios.contentInset</code> defaults to <code>never</code>.</td>\n</tr>\n<tr>\n<td>Android, Capacitor &lt;= 7</td>\n<td><code>android.adjustMarginsForEdgeToEdge</code> config could add native margins.</td>\n</tr>\n<tr>\n<td>Android, Capacitor 8+</td>\n<td><code>adjustMarginsForEdgeToEdge</code> removed. SystemBars core plugin (in <code>@capacitor/core</code>) handles insets.</td>\n</tr>\n<tr>\n<td>Android 15 (targetSdk 35)</td>\n<td>Edge-to-edge enforced; opt-out via <code>windowOptOutEdgeToEdgeEnforcement</code> still possible.</td>\n</tr>\n<tr>\n<td>Android 16 (targetSdk 36, Capacitor 8 default; 37 on Capacitor 9)</td>\n<td>Opt-out ignored. <code>@capacitor/status-bar</code> <code>overlaysWebView</code> and <code>backgroundColor</code> have no effect.</td>\n</tr>\n<tr>\n<td>Android WebView &lt; 140</td>\n<td><code>env(safe-area-inset-*)</code> wrong/0 (Chromium bug). SystemBars injects <code>--safe-area-inset-*</code> variables (default <code>insetsHandling: 'css'</code>).</td>\n</tr>\n</tbody>\n</table>\n<p>How SystemBars behaves on Android (from core source): if the page has <code>viewport-fit=cover</code> <strong>and</strong> WebView &gt;= 140, insets pass through to <code>env()</code> and the WebView is edge-to-edge. Otherwise Capacitor pads the WebView natively so content sits between the bars and <code>env()</code> reports 0. <code>--safe-area-inset-*</code> variables carry correct values in both cases when <code>insetsHandling</code> is <code>css</code>.</p>\n<h2>Workflow</h2>\n<ol>\n<li><strong>Inspect</strong>: <code>index.html</code> viewport meta, <code>capacitor.config.*</code> (<code>ios.contentInset</code>, <code>android.adjustMarginsForEdgeToEdge</code>, <code>plugins.SystemBars</code>, <code>plugins.StatusBar</code>), <code>@capacitor/core</code> + <code>@capacitor/status-bar</code> versions, <code>android/variables.gradle</code> <code>targetSdkVersion</code>, global CSS that sets <code>padding-top</code>, UI framework (Ionic / Konsta handle insets themselves).</li>\n<li><strong>Decide the design</strong>: full-bleed (draw under bars, pad content) vs. contained (content between bars). Ask the user if mockups are unclear.</li>\n<li><strong>Full-bleed (recommended)</strong>: <code>viewport-fit=cover</code> + the CSS fallback chain below, applied once at the layout shell, not per component.</li>\n<li><strong>Remove legacy config</strong>: delete <code>android.adjustMarginsForEdgeToEdge</code>; drop Android uses of <code>StatusBar.setOverlaysWebView</code> / <code>setBackgroundColor</code> (keep for iOS if wanted); prefer <code>SystemBars.setStyle</code> for icon color.</li>\n<li><strong>Framework check</strong>: Ionic already applies <code>--ion-safe-area-*</code>; Konsta uses <code>safeAreas</code>. Do not double-pad.</li>\n<li><strong>Verify</strong> on devices (below).</li>\n</ol>\n<p>Only load a reference when its topic is in play:</p>\n<ul>\n<li><a href=\"references/android-edge-to-edge.md\">references/android-edge-to-edge.md</a> - SystemBars config, status-bar migration, nav bar color, WebView version checks</li>\n<li><a href=\"references/css-patterns.md\">references/css-patterns.md</a> - layout shell, tab bars, reading insets in JS, debug overlay, resizable windows</li>\n</ul>\n<h2>Baseline</h2>\n<pre><code>&lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1, viewport-fit=cover\" /&gt;\n</code></pre>\n<pre><code>:root {\n  --sat: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));\n  --sar: var(--safe-area-inset-right, env(safe-area-inset-right, 0px));\n  --sab: var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));\n  --sal: var(--safe-area-inset-left, env(safe-area-inset-left, 0px));\n}\n.app-header { padding-top: var(--sat); padding-inline: var(--sal) var(--sar); }\n.app-tabbar { padding-bottom: var(--sab); padding-inline: var(--sal) var(--sar); }\n</code></pre>\n<p>The <code>--safe-area-inset-*</code> names are injected by Capacitor's SystemBars on Android; on iOS and web they are undefined, so the <code>env()</code> fallback applies.</p>\n<pre><code>import { SystemBars, SystemBarsStyle } from '@capacitor/core';\nawait SystemBars.setStyle({ style: SystemBarsStyle.Dark }); // light icons on dark background\n</code></pre>\n<p><code>SystemBarsStyle.Dark</code> = light content for dark backgrounds; <code>Light</code> = dark content. iOS needs <code>UIViewControllerBasedStatusBarAppearance = YES</code> (template default).</p>\n<h2>Traps</h2>\n<ul>\n<li>Missing <code>viewport-fit=cover</code> is the #1 cause of <code>env()</code> = 0 on iOS and of Capacitor padding the WebView on Android.</li>\n<li>Do not combine <code>ios.contentInset: 'always'</code> with CSS safe-area padding: insets apply twice.</li>\n<li>Do not hardcode 20/44/47/59 px status bar heights; heights differ per device, orientation, and window size.</li>\n<li>Insets change at runtime (rotation, iPad windowed mode, foldables, Android split screen, keyboard). Use CSS, or re-read on <code>resize</code>; never cache once at startup.</li>\n<li>On iOS the bottom inset stays while the keyboard is visible; use <code>max()</code> with keyboard height (see <code>capacitor-keyboard</code>).</li>\n<li><code>100vh</code> includes the area under system bars; use <code>100dvh</code> or flex layout with a fixed shell.</li>\n<li>Ionic: <code>ion-content</code> with <code>fullscreen</code> + <code>ion-header</code> already pads; adding body padding shifts everything twice.</li>\n</ul>\n<h2>Verification</h2>\n<ol>\n<li><code>npx cap sync</code>, run on: iPhone with Dynamic Island, iPhone SE-class (home button, small top inset), iPad (rotate + Stage Manager/windowed), Android 15/16 device or emulator in gesture <strong>and</strong> 3-button navigation, landscape.</li>\n<li>Check Android WebView version: <code>adb shell dumpsys package com.google.android.webview | grep versionName</code> (&lt; 140 relies on injected variables).</li>\n<li>In Safari Web Inspector / <code>chrome://inspect</code>, run:</li>\n</ol>\n<pre><code>getComputedStyle(document.documentElement).getPropertyValue('--sat');\ndocument.querySelector('meta[name=viewport]').content.includes('viewport-fit=cover');\n</code></pre>\n<ol start=\"4\">\n<li>Confirm no element overlaps bars; tab bar taps work above the gesture bar; no double padding.</li>\n<li>Grep for leftovers:</li>\n</ol>\n<pre><code>grep -rn \"adjustMarginsForEdgeToEdge\\|setOverlaysWebView\\|setBackgroundColor\\|windowOptOutEdgeToEdgeEnforcement\" capacitor.config.* src android/app/src/main/res 2&gt;/dev/null\n</code></pre>\n<h2>Error Handling</h2>\n<table>\n<thead>\n<tr>\n<th>Symptom / message</th>\n<th>Cause</th>\n<th>Fix</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Header under status bar on iOS, <code>env()</code> = 0</td>\n<td>No <code>viewport-fit=cover</code></td>\n<td>Add to viewport meta</td>\n</tr>\n<tr>\n<td>Android: content correct but no edge-to-edge, <code>env()</code> = 0</td>\n<td>No <code>viewport-fit=cover</code> or WebView &lt; 140, so Capacitor pads natively</td>\n<td>Add <code>viewport-fit=cover</code>; use <code>--safe-area-inset-*</code> fallback</td>\n</tr>\n<tr>\n<td>Android: double gap at top</td>\n<td>Native padding + your CSS padding with <code>insetsHandling: 'disable'</code> or custom MainActivity insets code</td>\n<td>Remove custom <code>setDecorFitsSystemWindows</code> / inset listeners; keep SystemBars default</td>\n</tr>\n<tr>\n<td><code>StatusBar.setBackgroundColor</code> / <code>setOverlaysWebView</code> no effect on Android</td>\n<td>targetSdk 35+/36 edge-to-edge</td>\n<td>Draw a background under the bar in CSS; use <code>SystemBars.setStyle</code> for icon color</td>\n</tr>\n<tr>\n<td><code>android.adjustMarginsForEdgeToEdge</code> still in config after Capacitor 8 upgrade, margins gone</td>\n<td>Option removed and ignored</td>\n<td>Delete it; rely on SystemBars + CSS</td>\n</tr>\n<tr>\n<td>Logcat <code>Unknown insetsHandling value '...'. Falling back to 'css'.</code></td>\n<td>Invalid <code>SystemBars.insetsHandling</code></td>\n<td>Use a value listed in the current docs (<code>css</code>, <code>disable</code>; newer cores also accept <code>native</code>)</td>\n</tr>\n<tr>\n<td>Status bar text invisible (white on white)</td>\n<td>Style mismatch</td>\n<td><code>SystemBars.setStyle({ style: SystemBarsStyle.Light })</code></td>\n</tr>\n<tr>\n<td>Layout jumps on first paint (Android)</td>\n<td>SystemBars detects <code>viewport-fit</code> after page commit</td>\n<td>Set <code>plugins.SystemBars.initialViewportFitValueHint: 'cover'</code> (in core config declarations; verify in your version)</td>\n</tr>\n</tbody>\n</table>\n<h2>Resources</h2>\n<ul>\n<li>System Bars API: <a href=\"https://capacitorjs.com/docs/apis/system-bars\">https://capacitorjs.com/docs/apis/system-bars</a></li>\n<li>Status Bar API (Android 16 note): <a href=\"https://capacitorjs.com/docs/apis/status-bar\">https://capacitorjs.com/docs/apis/status-bar</a></li>\n<li>Updating to 8.0: <a href=\"https://capacitorjs.com/docs/updating/8-0\">https://capacitorjs.com/docs/updating/8-0</a></li>\n<li>Android edge-to-edge: <a href=\"https://developer.android.com/develop/ui/views/layout/edge-to-edge\">https://developer.android.com/develop/ui/views/layout/edge-to-edge</a></li>\n<li>WebKit viewport-fit / env(): <a href=\"https://webkit.org/blog/7929/designing-websites-for-iphone-x/\">https://webkit.org/blog/7929/designing-websites-for-iphone-x/</a></li>\n</ul>\n","files":[{"path":"metadata.json","sizeBytes":996,"isText":true},{"path":"references/android-edge-to-edge.md","sizeBytes":3465,"isText":true},{"path":"references/css-patterns.md","sizeBytes":3344,"isText":true},{"path":"SKILL.md","sizeBytes":9366,"isText":true}],"reviewScore":null,"reviewSummary":null,"trust":{"provenance":"trusted-source-unreviewed","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow.","bodySource":null},"bodyLocked":false,"purchaseUrl":null,"sourceUrl":null,"report":{"provenance":"trusted-source-unreviewed","screen":{"ran":true,"outcome":"clean","suspicious":0,"notes":0,"hiddenCharacters":false},"virusScan":{"engine":"clamav","status":"clean","scannedAt":"2026-12-05T18:20:16.45777Z","sha256":"138D7A1F6DF46D1A646D9FA14F4126DAE0D668B88028981400F129AB1DFBDD23","sizeBytes":8016},"review":null,"source":{"repositoryUrl":"https://github.com/Cap-go/capgo-skills","path":"skills/safe-area-handling","license":"MIT","commit":"76462e3a0041ee8dd0d370c344d9fd3ae2c29cdb","subtreeSha":"ED69ABF04F5D74F1B0C028804046E4BFB87A56B1A270A2BC5B5E1C7836738EF5","lastSyncedAt":"2026-12-05T18:17:06.651351Z"},"reviewedAt":"2026-12-05T18:25:15.667473Z","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow."},"install":[{"target":"skills-cli","command":"npx skills add https://github.com/Cap-go/capgo-skills/tree/main/skills/safe-area-handling"},{"target":"claude-code","command":"claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install cap-go-capgo-skills@llmmart"},{"target":"git","command":"git clone https://github.com/Cap-go/capgo-skills.git"}]}