Implement automatic light and dark mode using CSS custom properties and theDocumentation Index
Fetch the complete documentation index at: https://setup.despia.com/llms.txt
Use this file to discover all available pages before exploring further.
prefers-color-scheme media query. The Despia runtime handles status bar text color natively through the color-scheme CSS property, so theming requires no SDK calls.
Installation
- Bundle
- CDN
Despia Editor setup
Configure these values in the Despia Editor before writing CSS. The order matters, fullscreen mode and Auto-Inject Safe Area must be set together to avoid double padding.Enable Fullscreen Mode
Toggle Fullscreen Mode on. This removes the native status bar background, giving CSS full control over the status bar region. Without this, you cannot extend your app’s background up behind the status bar.
Disable Auto-Inject Safe Area
Toggle Auto-Inject Safe Area off. With Fullscreen Mode on, you apply
--safe-area-top and --safe-area-bottom yourself in CSS. Leaving Auto-Inject on as well produces double padding and broken layouts.Set Light Mode status bar text color
Set Light Mode Status Bar Text Color to Black. Dark text is readable over the light backgrounds your light theme uses.
Set Dark Mode status bar text color
Set Dark Mode Status Bar Text Color to White. Light text is readable over the dark backgrounds your dark theme uses.
Save and rebuild
Save your changes, then trigger a fresh build from the Despia Editor. Status bar settings are written into native Info.plist entries and signed into the app binary, so they cannot be applied over-the-air. After the rebuild, the CSS-side work below picks up the configuration automatically.
How it works
Fullscreen mode removes the native status bar background, giving CSS full control over that region. Thecolor-scheme property tells the native container whether to render status bar text in light or dark style, switched automatically by prefers-color-scheme. The Despia runtime also injects --safe-area-top and --safe-area-bottom CSS variables before your app starts, so they are available synchronously with no loading state.
CSS color tokens
Define light tokens in:root and override them inside the dark mode media query. Setting color-scheme in both blocks switches the native status bar text style automatically, with no SDK call required.
Safe area handling
With Fullscreen Mode enabled and Auto-Inject Safe Area disabled, your CSS owns the status bar and home indicator regions. Safe areas are insets, so they stack on top of your existing padding rather than replacing it. Always combine them with your base padding usingcalc().
The full pattern pairs the Despia runtime variable with env(safe-area-inset-*) as a fallback, with 0px as the final fallback inside env(). The runtime variable applies inside the native container, the env value applies during web preview, and the 0px keeps the calc() valid when neither is present.
Runtime status bar override
In most casescolor-scheme handles status bar text color automatically. For one-off runtime overrides, such as navigating to a screen with a hardcoded background that ignores your CSS tokens, the SDK exposes a direct command. Always gate the call behind an isDespia check so it is a no-op in the browser.
Manual theme toggles and animation timing
If you ship a manual theme toggle that overrides the system theme (a sun/moon button independent ofprefers-color-scheme), you need to call statusbartextcolor:// strictly after your CSS animation finishes. Calling it during the transition, or even slightly before it begins, will fail.
This is an iOS-level guard, not a Despia limitation. The SDK successfully issues the command in every case, but iOS inspects the on-screen colors at the moment the request lands. If the interface is still showing the old theme (because the animation has not started yet, or is still mid-flight), the system decides the new status bar text color would look wrong against what is currently visible and silently rejects the change. No error is thrown. The result is unreadable text, white-on-white in light mode or black-on-black in dark mode.
Wait for the transition to complete, then call the SDK.
transitionend event, fall back to setTimeout matching your transition duration:
color-scheme and prefers-color-scheme, the native runtime handles the switch atomically with the OS theme change and there is nothing to wait for.
Resources
NPM Package
despia-native