Document.preferredStyleSheetSet returns the author’s preferred style sheet set name (MDN). If none is defined, it returns "".
Read the notes below before you get or set this property. Prefer feature detection when support is limited.
Syntax
Use document.preferredStyleSheetSet. Start with this line.
JavaScript
document.preferredStyleSheetSet
Call
What it does
document.preferredStyleSheetSet
Primary signature.
Built into the browser. Read or assign document.preferredStyleSheetSet — no import required.
Library declarations
JavaScript
document.preferredStyleSheetSet
Parameters
Parameter
Description
Setter
Optional. Read-only author default
Modern path
Required. Class / CSS / adoptedStyleSheets
Return Value
Return Value
Description
*
The current value of document.preferredStyleSheetSet.
JavaScript Examples
Example 1 — Read preferredStyleSheetSet
MDN-style check — log the name or report that none exists.
JavaScript
if (document.preferredStyleSheetSet) {
console.log(
"The preferred style sheet set is: " + document.preferredStyleSheetSet
);
} else {
console.log("There is no preferred style sheet.");
}
Branch. Log the value only when the getter exists.
Expect gaps. Deprecated non-standard APIs are often incomplete.
Do not polyfill. Migrate themes instead of shimming this API.
Example 3 — Prefer a Modern Theme Toggle
Simple replacement pattern for light/dark themes without style sheet sets.
JavaScript
// Prefer this over preferredStyleSheetSet for new apps
document.documentElement.classList.toggle("dark");
console.log(
document.documentElement.classList.contains("dark")
);
Toggle a class. Put theme styles under .dark (or similar).
Target documentElement. The <html> root is the usual place.
Standard APIs. Works everywhere without alternate stylesheet menus.
Pair with CSS. Custom properties and prefers-color-scheme complete the story.
Compatibility
Browser Support
Document.preferredStyleSheetSet is Deprecated and Non-standard (MDN). Support is incomplete — feature-detect, and do not ship new features on it.
✓ Deprecated · Non-standard
Document.preferredStyleSheetSet
Legacy author preferred style sheet set name — avoid in new apps.
LegacyAvoid in new apps
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
preferredStyleSheetSetDeprecated
Bottom line: Safe to recognize in old code. For themes: documentElement classes, CSS variables, prefers-color-scheme, or adoptedStyleSheets.
Frequently Asked Questions
The author’s preferred style sheet set name. MDN: it is determined from stylesheet order and the Default-Style HTTP header. If none is defined, it returns the empty string ("").
Yes. MDN marks Document.preferredStyleSheetSet as Deprecated and Non-standard. Do not use it in new projects.
Historically with titled stylesheets: a preferred set used rel="stylesheet" plus title, and alternates used rel="alternate stylesheet" plus title. The Default-Style HTTP header could also influence the choice (MDN).
No. preferredStyleSheetSet returns "" when there is no author preferred set. Related legacy APIs use null in other cases (for example lastStyleSheetSet).
Prefer a class on document.documentElement, CSS custom properties, prefers-color-scheme, or adoptedStyleSheets. Avoid the alternate style sheet set DOM API for new work.
No. It is a read-only author default. Legacy switching used selectedStyleSheetSet or enableStyleSheetsForSet() — both are also legacy; prefer modern CSS themes.