Toggle a class. CSS (or later styles) can key off .dark.
Read the state.classList.contains reports the current theme.
Why this wins. Standard, widely supported, and easy to persist—unlike style sheet sets.
Compatibility
Browser Support
Document.lastStyleSheetSet is Deprecated and Non-standard on MDN. Support is limited and unreliable across modern browsers.
✓ Deprecated · Non-standard
Document.lastStyleSheetSet
Legacy last enabled style sheet set name — null until selectedStyleSheetSet changes; often unavailable.
LowLegacy / limited
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
Android WebViewSupported · Modern WebView
Full support
lastStyleSheetSetAvoid
Bottom line: Do not build new theme UIs on this API. Feature-detect if you must read legacy pages. Prefer documentElement class toggles, CSS, matchMedia, or adoptedStyleSheets.
Frequently Asked Questions
The last enabled style sheet set name. The value changes when document.selectedStyleSheetSet is changed. If selectedStyleSheetSet has never been set, the value is null (MDN).
Yes. MDN marks Document.lastStyleSheetSet as Deprecated and Non-standard. Do not use it in new projects.
No. MDN notes that this value does not change when document.enableStyleSheetsForSet() is called — only when selectedStyleSheetSet is changed.
If the selected set was never changed via selectedStyleSheetSet, MDN says the value is null. Many modern browsers also never implemented (or removed) the alternate style sheet set API.
Prefer toggling a class on document.documentElement, CSS custom properties, prefers-color-scheme via matchMedia, or adoptedStyleSheets.
Only to understand legacy code. New theme switching should use CSS and standard DOM APIs, not style sheet sets.