JavaScript Document preferredStyleSheetSet Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Property

Definition

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
CallWhat it does
document.preferredStyleSheetSetPrimary signature.

Built into the browser. Read or assign document.preferredStyleSheetSet — no import required.

Library declarations
JavaScript
document.preferredStyleSheetSet

Parameters

ParameterDescription
SetterOptional. Read-only author default
Modern pathRequired. Class / CSS / adoptedStyleSheets

Return Value

Return ValueDescription
*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.");
}
Try It Yourself

How It Works

  1. Read the getter. Returns a string name or "".
  2. Truthy check. Empty string is falsy — treated as “no preferred set”.
  3. Legacy only. Useful for auditing old alternate-stylesheet pages.
  4. May be missing. Some engines remove this non-standard API.

Example 2 — Feature Detect Safely

Always check existence before reading — the API is non-standard.

JavaScript
const supported = "preferredStyleSheetSet" in document;
console.log(supported);

if (supported) {
  console.log(JSON.stringify(document.preferredStyleSheetSet));
} else {
  console.log("API not available");
}
Try It Yourself

How It Works

  1. Use in. Safer than reading a missing property.
  2. Branch. Log the value only when the getter exists.
  3. Expect gaps. Deprecated non-standard APIs are often incomplete.
  4. 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")
);
Try It Yourself

How It Works

  1. Toggle a class. Put theme styles under .dark (or similar).
  2. Target documentElement. The <html> root is the usual place.
  3. Standard APIs. Works everywhere without alternate stylesheet menus.
  4. Pair with CSS. Custom properties and prefers-color-scheme complete the story.

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.

Legacy Avoid in new apps
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Android WebView Supported · Modern WebView
Full support
preferredStyleSheetSet Deprecated

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.

Next: selectedStyleSheetSet

Learn the currently selected style sheet set name.

selectedStyleSheetSet tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful