On this page
Switch light and dark mode
Use skin helpers and CSS to follow the chosen mode.
Before you begin: Offer theme skins.
Skin Mode API
frontbacked.js exposes skin helpers:
Reference excerpt: use this with the page, variables and functions described in this guide. Try a complete example →
toggleSkinMode() switches between light and dark when both exist. For custom modes, it cycles through the modes listed for the skin.
Frontbacked updates the data-frontbacked-skin link and saves only the visitor's mode preference. Site owners choose the skin from fb-admin.
Frontbacked does not expose public visitor setSkin or toggleSkin methods to themes. A theme should not let visitors choose a different skin; it should only let them switch the mode of the skin chosen by the site owner. For authenticated admin UIs, Frontbacked.skins.setSiteSkin(skinId) can update the site-selected skin through the protected admin endpoint, while Frontbacked.skins.current() and Frontbacked.skins.list() let the UI show the current skin and available choices.
Light and dark button
Add f-skin-mode-toggle to a button and Frontbacked does the rest. No script is needed:
- A click switches between the skin's light and dark modes and remembers the visitor's choice.
- The button is hidden while the site's skin has only one mode, from the first paint.
- The button gets
aria-pressed="true"in dark mode anddata-skin-modewith the current mode, and<html>getsdata-frontbacked-skin-mode, so CSS can swap the icons. Prefer the<html>attribute, which also covers buttons added after the page loads:
The chat button sits at the bottom right of every page, so a floating mode button reads best at the bottom left.
CSS Pattern
Keep shared layout CSS in your normal theme CSS. Put visual differences in skins:
This keeps skins small and makes it easier to add more looks without duplicating pages or JavaScript.
Continue with Add a language button.