AI Prompt
Add light and dark mode to my app using CSS
In the Despia editor, before writing any code:
prefers-color-scheme and the Despia runtime safe area variables.In the Despia editor, before writing any code:
- Under Status Bar settings, enable Fullscreen Mode
- Disable Auto-Inject Safe Area so you can manage padding yourself in CSS
- Set the Light Mode status bar text color to Black and the Dark Mode status bar text color to White in the editor. These are managed natively and must be configured here rather than in code
- Define light and dark color tokens in
:rootusing CSS custom properties - Override them inside
@media (prefers-color-scheme: dark). Do not use JavaScript state or a custom toggle - Set
color-scheme: lightin:rootandcolor-scheme: darkinside the media query. This tells the native container to render the status bar text as black in light mode and white in dark mode automatically - Fullscreen mode removes the status bar background entirely. Use
padding-top: var(--safe-area-top)on your header to fill that space with your own background color via CSS. Applypadding-bottom: var(--safe-area-bottom)to your footer the same way. These variables are injected by the Despia runtime
padding-top: var(--safe-area-top) ensures your content sits below it. The CSS color-scheme property signals to the native container which status bar text style to use, with no SDK call required. The prefers-color-scheme media query handles all visual theming automatically based on the user’s OS setting. The Despia runtime injects --safe-area-top and --safe-area-bottom CSS variables before your app starts, so they are available synchronously with no loading state.
Despia Editor Setup
Before writing any CSS, configure the following in the Despia dashboard under Status Bar settings:| Setting | Value | Why |
|---|---|---|
| Fullscreen Mode | Enabled | Removes the status bar background so you can manage that area yourself in CSS using the safe area insets |
| Auto-Inject Safe Area | Disabled | Lets you apply --safe-area-top and --safe-area-bottom yourself in CSS |
| Light Mode Status Bar Text Color | Black | Ensures readable dark text over your light background |
| Dark Mode Status Bar Text Color | White | Ensures readable light text over your dark background |
Usage
CSS Color Tokens
Define your light and dark color tokens in:root and override them for dark mode. The color-scheme property controls the native status bar text color automatically.
Safe Area Insets
With fullscreen mode enabled and Auto-Inject Safe Area disabled, the status bar background is gone and you own that space. Use--safe-area-top on your header so its background color fills the status bar area, and --safe-area-bottom on your footer to clear the home indicator:
Full Example
A complete CSS setup combining theming and safe area handling:Optional: statusbartextcolor:// SDK Override
In most cases color-scheme handles status bar text color automatically and no SDK call is needed. The correct default should be configured in the Despia editor under Status Bar settings rather than set in code.
If you have a specific runtime override case, for example navigating to a screen with a hardcoded background that does not follow your CSS tokens, the SDK command is available:
Resources
- NPM Package
- View full NPM documentation for additional configuration options