Resolution checks the fixed theme URL query, the supplied local-storage
key, the current prefers-color-scheme media query, and finally the fixed
light fallback. Query values accept only light and dark. Storage also
accepts system, which resolves to a concrete value while retaining the
System label. A valid query preference is written under the supplied
storage key when browser storage is available; resolution still succeeds
when the write fails.
The concrete light or dark value and the label of the preference that selected it.
Throws
If storageKey is not a non-empty string.
Remarks
Safe during SSR and resilient to unavailable or throwing browser APIs. A valid URL preference is written to storage when possible; other resolution paths remain read-only. The function never mutates the DOM or adds listeners.
Resolve the current website theme.
Resolution checks the fixed
themeURL query, the supplied local-storage key, the currentprefers-color-schememedia query, and finally the fixedlightfallback. Query values accept onlylightanddark. Storage also acceptssystem, which resolves to a concrete value while retaining theSystemlabel. A valid query preference is written under the supplied storage key when browser storage is available; resolution still succeeds when the write fails.Resolution matrix:
darklight{ value: "dark", label: "Dark" }lightdark{ value: "light", label: "Light" }dark{ value: "dark", label: "Dark" }light{ value: "light", label: "Light" }system{ value: "dark", label: "System" }system{ value: "light", label: "System" }{ value: "dark", label: "System" }{ value: "light", label: "System" }{ value: "light", label: "Light" }Usage:
Possible output: