Document.preferredStyleSheetSet is a deprecated, non-standard instance property that returns the page author’s preferred style sheet set name, or the empty string when none is defined. Learn how it differs from selectedStyleSheetSet and lastStyleSheetSet, and what to use instead for themes.
01
Kind
Instance property
02
Returns
string ("" if none)
03
Status
Deprecated
04
Also
Non-standard
05
Author default
From markup order
06
Prefer
CSS themes
Fundamentals
Introduction
Years ago, HTML offered alternate stylesheets with <link rel="stylesheet" title="..."> and rel="alternate stylesheet". The page author could mark one named set as the default. preferredStyleSheetSet exposes that author-chosen default.
MDN: the property returns the preferred style sheet set as set by the page author. This is determined from the order of style sheet declarations and the Default-Style HTTP header. If there isn’t a preferred style sheet set defined by the author, the empty string ("") is returned.
💡
Author default vs user selection
preferredStyleSheetSet is the author’s default. selectedStyleSheetSet is what the user (or script) currently has active. They are related but not the same concept.
A read-only instance property from the legacy style sheet set API.
Value — preferred set name string, or "" if none defined (MDN).
Read-only — reflects author markup / headers; not for assigning themes.
Source — stylesheet order and Default-Style HTTP header (MDN).
Status — Deprecated and Non-standard (MDN).
Support — often missing; always feature-detect.
Foundation
📝 Syntax
JavaScript
document.preferredStyleSheetSet
Value
A string naming the author’s preferred style sheet set, or "" when no preferred set is defined (MDN).
MDN example
JavaScript
if (document.preferredStyleSheetSet) {
console.log(
`The preferred style sheet set is: ${document.preferredStyleSheetSet}`
);
} else {
console.log("There is no preferred style sheet.");
}
Because MDN marks the API deprecated and non-standard, missing support is normal.
Example 2 — Safely Read the Property
Guard with feature detection before logging.
JavaScript
if ("preferredStyleSheetSet" in document) {
const preferred = document.preferredStyleSheetSet;
console.log(preferred === "" ? "(empty — no author default)" : preferred);
} else {
console.log("Property not available in this browser");
}
MDN returns "" when the author did not define a preferred set—not null.
📈 MDN Pattern, Compare & Modern Themes
Legacy behavior notes and the recommended replacement.
Example 3 — MDN: Log Preferred Set or Fallback
Use truthiness to distinguish a named set from the empty string (MDN example).
JavaScript
if ("preferredStyleSheetSet" in document) {
if (document.preferredStyleSheetSet) {
console.log(
`The preferred style sheet set is: ${document.preferredStyleSheetSet}`
);
} else {
console.log("There is no preferred style sheet.");
}
}
An empty string is falsy in JavaScript, so MDN’s if (document.preferredStyleSheetSet) cleanly branches.
Example 4 — Compare Preferred, Selected, and Last
Inspect all three legacy set properties together.
JavaScript
function reportStyleSheetSets() {
if (!("preferredStyleSheetSet" in document)) {
return "Style sheet set API not supported";
}
return {
preferred: document.preferredStyleSheetSet,
selected: document.selectedStyleSheetSet,
last: document.lastStyleSheetSet
};
}
console.log(reportStyleSheetSets());
This pattern works in every modern browser without deprecated Document properties.
Applications
🚀 Common Use Cases
Legacy audits — detect whether old sites declared an author-preferred theme.
Migration planning — map preferredStyleSheetSet to a CSS class default.
Teaching history — explain alternate stylesheets vs modern themes.
Feature detection — branch away from style sheet set APIs when missing.
Do not use for new themes — prefer CSS / classList.
Code reviews — flag deprecated API usage in maintenance work.
🧠 How Author Preferred Sets Were Chosen
1
Author links stylesheets with titles
Persistent and alternate <link> elements form named sets.
Markup
2
Browser picks author default
Order of declarations and Default-Style header choose the preferred set (MDN).
Default
3
You read preferredStyleSheetSet
Returns the set name, or "" if the author did not define one.
Query
4
✓
Today: use CSS themes instead
Toggle classes or custom properties for reliable, standard theme switching.
Important
📝 Notes
MDN: Deprecated and Non-standard — both banners shown above.
Returns "", not null, when no author preferred set exists (MDN).
Often unavailable in Chromium and other modern engines.
Pair learning with lastStyleSheetSet and selectedStyleSheetSet for full legacy context.
Prefer class-based themes or adoptedStyleSheets for new work.
Compatibility
Browser Support
Document.preferredStyleSheetSet is marked Deprecated and Non-standard on MDN. Do not rely on it in new apps. Logos use the shared browser-image-sprite.png sprite from this project.
✓ Deprecated · Non-standard
Document.preferredStyleSheetSet
Legacy author preferred style sheet set name — or empty string when none defined.
LegacyAvoid in new code
Google ChromeGenerally not available
No / removed
Mozilla FirefoxLegacy / may be limited
Legacy only
Apple SafariNot reliable
No / limited
Microsoft EdgeChromium — generally not available
No / removed
OperaFollow Chromium
No / removed
Internet ExplorerLegacy era only
Legacy only
Document.preferredStyleSheetSetLimited / removed
Bottom line: Feature-detect if you must read legacy code. Prefer CSS class themes, custom properties, or adoptedStyleSheets for modern theme switching.
Wrap Up
Conclusion
Document.preferredStyleSheetSet exposes the page author’s default style sheet set name, or "" when none is defined. MDN marks it deprecated and non-standard, so treat it as history—build new themes with CSS classes and standard Document APIs instead.
Feature-detect before reading preferredStyleSheetSet
Treat "" as “no author default” (MDN)
Use class toggles / CSS variables for themes
Prefer adoptedStyleSheets for constructable CSS
Migrate legacy alternate-stylesheet UIs when you find them
❌ Don’t
Build new products on style sheet set APIs
Assume Chromium exposes preferredStyleSheetSet
Confuse preferred (author) with selected (active) sets
Expect null instead of "" for no default
Confuse this with document.styleSheets (live stylesheet list)
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about document.preferredStyleSheetSet
Author default set name — not for new code.
5
Core concepts
📄01
Returns
string / ""
API
⚠️02
Status
Deprecated
MDN
🚫03
Also
Non-standard
Avoid
🛠04
Source
Author markup
Default
🎨05
Prefer
CSS themes
Modern
❓ Frequently Asked Questions
The author's preferred style sheet set name as defined by the page author. If no preferred set is defined, MDN says the empty string ("") is returned.
Yes. MDN marks Document.preferredStyleSheetSet as Deprecated and Non-standard. Do not use it in new code.
MDN: from the order of style sheet declarations and the Default-Style HTTP header. The first persistent stylesheet with a title often becomes the preferred set in supporting browsers.
No. preferredStyleSheetSet returns "" when the author did not define a preferred set. lastStyleSheetSet returns null when selectedStyleSheetSet was never changed (MDN).
Prefer toggling a class on document.documentElement (for example dark), CSS custom properties, prefers-color-scheme, or adoptedStyleSheets for constructable stylesheets.
No meaningful assignment. It is a read-only author default. To switch themes in the legacy API, use selectedStyleSheetSet or enableStyleSheetsForSet() — but prefer modern CSS for new work.
Did you know?
The empty string ("") and null mean different things in this legacy API family: preferredStyleSheetSet uses "" when the author did not define a default, while lastStyleSheetSet returns null when the user never changed the selection.