How to Add Dark Mode to Power Apps
Dark mode isn't just a nice-to-have anymore - users expect it. In this tutorial, you'll learn how to add a professional dark/light mode toggle to your Power Apps in about 10 minutes.
What you'll build:
- A working dark/light mode toggle
- Colors that automatically switch when the theme changes
- A professional-looking app that respects user preferences
Time needed: ~10 minutes
The Quick Way: Use an App Shell
The fastest way to add dark mode is to use a PowerLibs App Shell that has it built-in. These components handle all the complexity for you. The App Shells need a paid plan; the manual way further down works on any account.
Step 1: Go to App Shells
Visit the App Shells section and pick any shell. Every one of them has a theme switch built in:
- Sidebar App Shell or Collapsible Sidebar App Shell for desktop-first apps
- Top Nav App Shell or Portal App Shell for lighter tools and portals
- Mobile App Shell for phone-first apps, Split View App Shell for list and detail
Every shell is responsive: below 768 px the sidebar or tabs hide and a bottom tab bar appears. Nothing to set up for phones.
Step 2: Customize Your Settings
Click Customize and notes on your chosen App Shell and use the Customize panel to configure:
- What's in the frame - keep the Theme switch part on
- App name and logo icon
- Navigation items - label, icon, and an optional screen to navigate to
Every surface color in the YAML is a formula such as If(gblShellDark, dark, light), so the whole frame flips when the user taps the sun or moon icon. You do not set two color schemes, and there is no OnStart code to paste. If you switch the Theme switch part off, the YAML has plain colors in the preview theme and no dark variable.
Step 3: Copy the YAML Code
Click Copy YAML. This copies everything you need.
Step 4: Paste into Power Apps
- Open Power Apps Studio
- In the Tree view panel, select the screen
- Press Ctrl+V (Cmd+V on a Mac), or choose "Paste" in the screen's ... menu
The entire app shell appears with the theme toggle already working.
Step 5: Use the Theme in Your Own Controls
The shell switches its own colors. To make your own controls follow, read the same variable. Put a formula like this in the Fill property of a container or card of yours:
If(gblShellDark, RGBA(21, 30, 48, 1), RGBA(255, 255, 255, 1))
gblShellDark is the variable of the Sidebar App Shell. Every shell has its own, so two shells never clash: gblRailShellDark (Collapsible Sidebar), gblTopShellDark (Top Nav), gblMobileShellDark (Mobile), gblPortalShellDark (Portal) and gblSplitShellDark (Split View). The names use your prefix settings.
The variable is blank until someone taps the switch, so the app opens in light mode, whatever theme the preview showed.
Step 6: Done!
Your app now has working dark mode. Click the sun or moon icon in the shell to switch between light and dark.
The Manual Way: Add Dark Mode to Any App
If you want to add dark mode to an existing app or build it yourself, here's how.
Step 1: Create Theme Variables
Add these variables to your App.OnStart. ColorValue turns the hex text into a color, which is what Fill and Color properties expect:
// Theme toggle (false = light, true = dark)
Set(varDarkMode, false);
// Background colors
Set(varBgPrimary, ColorValue(If(varDarkMode, "#0f172a", "#ffffff")));
Set(varBgSecondary, ColorValue(If(varDarkMode, "#1e293b", "#f1f5f9")));
// Text colors
Set(varTextPrimary, ColorValue(If(varDarkMode, "#f8fafc", "#0f172a")));
Set(varTextSecondary, ColorValue(If(varDarkMode, "#94a3b8", "#64748b")));
// Accent color (same for both themes usually)
Set(varAccentColor, ColorValue("#3b82f6"));
After adding OnStart code, you need to run it once. Right-click on App in the Tree view and select "Run OnStart".
Step 2: Create a Toggle Button
Add a button or icon that toggles the theme:
// OnSelect property of your toggle button
Set(varDarkMode, !varDarkMode);
// Re-run the color assignments
Set(varBgPrimary, ColorValue(If(varDarkMode, "#0f172a", "#ffffff")));
Set(varBgSecondary, ColorValue(If(varDarkMode, "#1e293b", "#f1f5f9")));
Set(varTextPrimary, ColorValue(If(varDarkMode, "#f8fafc", "#0f172a")));
Set(varTextSecondary, ColorValue(If(varDarkMode, "#94a3b8", "#64748b")));
Step 3: Apply Variables to Your Components
Instead of hardcoding colors, use your variables:
| Property | Use This |
|---|---|
| Screen Fill | varBgPrimary |
| Card Fill | varBgSecondary |
| Text Color | varTextPrimary |
| Subtle Text | varTextSecondary |
| Button Color | varAccentColor |
For example, set your screen's Fill property to:
varBgPrimary
And text labels' Color property to:
varTextPrimary
Step 4: Test It
Click your toggle button. All components using the variables will switch colors instantly.
Tips for Better Dark Mode
Use Sufficient Contrast
Dark mode isn't just "invert everything". Make sure:
- Text is easily readable against backgrounds
- Interactive elements stand out
- Don't use pure black (
#000000) - use dark grays like#0f172a
Don't Forget Borders
In light mode, you might have subtle gray borders. In dark mode, you'll need lighter borders:
Set(varBorderColor, ColorValue(If(varDarkMode, "#334155", "#e2e8f0")));
Consider Images and Icons
Icons and images might need adjustment:
- SVG icons can have their colors changed with formulas
- For images, consider having dark/light variants
- Or use a slight overlay to reduce brightness in dark mode
Next Steps
Now that you have dark mode working:
- Add more screens - They'll all use your theme variables
- Customize the colors - Adjust the hex values to match your brand
- Save user preference - Use
SaveData()to remember the user's choice
Want a complete app layout with dark mode already built in? Check out the App Shell components - they include navigation, headers, and theme switching all ready to go.
Related Components
- App Shells - App frames, each with a theme switch built in
- Navigation Bars - Headers for your app
Have questions about this tutorial? Send feedback and I'll help you out.