JavaScript Document preferredStyleSheetSet Property

Beginner
⏱️ 12 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Deprecated
Non-standard
Instance property

What You’ll Learn

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

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.

Related Document tutorials: lastStyleSheetSet, adoptedStyleSheets, documentElement, Document constructor.

Understanding Document.preferredStyleSheetSet

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.

📝 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.");
}

Example markup that defines sets

HTML
<link rel="stylesheet" href="default.css" title="Default">
<link rel="alternate stylesheet" href="dark.css" title="Dark">
<link rel="alternate stylesheet" href="large.css" title="Large print">

⚡ Quick Reference

GoalCode / note
Feature-detect"preferredStyleSheetSet" in document
Read author defaultdocument.preferredStyleSheetSet
No preferred set?Returns "" (MDN)
User’s current setdocument.selectedStyleSheetSet
Modern themedocument.documentElement.classList.toggle("dark")
MDN statusDeprecated & Non-standard

🔍 At a Glance

Four facts about document.preferredStyleSheetSet.

Type
string

Author default

Empty
""

No preferred set

Status
deprecated

Avoid

Prefer
CSS class

Themes

📋 Preferred vs Selected vs Last

preferredStyleSheetSetselectedStyleSheetSetlastStyleSheetSet
Who sets it?Page author (markup / header)User or scriptUpdated when selected changes
Writable?No (read-only)Yes (MDN)No
Empty meansNo author default ("")Context-dependentNever changed (null)
Use in 2026?NoNoNo

Examples Gallery

Examples follow MDN Document: preferredStyleSheetSet. Many browsers will report the property as missing—that is expected.

📚 Getting Started

Detect support and safely read the legacy property.

Example 1 — Feature Detect preferredStyleSheetSet

Never assume the property exists.

JavaScript
const supported = "preferredStyleSheetSet" in document;
console.log("preferredStyleSheetSet supported?", supported);
Try It Yourself

How It Works

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");
}
Try It Yourself

How It Works

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

How It Works

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());
Try It Yourself

How It Works

preferred is the author default; selected is active now; last tracks prior selection changes.

Example 5 — Modern Theme Class Toggle (Recommended)

Replace alternate stylesheets with a standard class on <html>.

JavaScript
document.getElementById("theme-btn").addEventListener("click", () => {
  document.documentElement.classList.toggle("dark");
  const isDark = document.documentElement.classList.contains("dark");
  console.log("theme:", isDark ? "dark" : "light");
});
Try It Yourself

How It Works

This pattern works in every modern browser without deprecated Document properties.

🚀 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.

📝 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.

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.

Legacy Avoid in new code
Google Chrome Generally not available
No / removed
Mozilla Firefox Legacy / may be limited
Legacy only
Apple Safari Not reliable
No / limited
Microsoft Edge Chromium — generally not available
No / removed
Opera Follow Chromium
No / removed
Internet Explorer Legacy era only
Legacy only
Document.preferredStyleSheetSet Limited / removed

Bottom line: Feature-detect if you must read legacy code. Prefer CSS class themes, custom properties, or adoptedStyleSheets for modern theme switching.

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.

Continue with selectedStyleSheetSet, lastStyleSheetSet, adoptedStyleSheets, or the JavaScript hub.

💡 Best Practices

✅ Do

  • 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)

Key Takeaways

Knowledge Unlocked

Five things to remember about document.preferredStyleSheetSet

Author default set name — not for new code.

5
Core concepts
⚠️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.

Next: selectedStyleSheetSet

Learn the legacy property for the currently active style sheet set.

selectedStyleSheetSet →

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.

6 people found this page helpful