JavaScript Document enableStyleSheetsForSet() Method

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

What You’ll Learn

document.enableStyleSheetsForSet() is a deprecated, non-standard instance method that enables stylesheet titles matching a set name (see MDN Document: enableStyleSheetsForSet()). Learn the name rules, empty string vs null, what stays enabled, how it differs from selectedStyleSheetSet, modern alternatives, and five try-it labs.

01

Kind

Instance method

02

Arg

name (string)

03

Returns

undefined

04

Matches

link/style title

05

Status

Deprecated

06

Also

Non-standard

Introduction

Years ago, browsers exposed alternate stylesheets<link rel="stylesheet" title="Dark"> themes users or scripts could switch. enableStyleSheetsForSet(name) was one way to turn a named set on and turn other titled sheets off.

MDN: it enables stylesheets matching the specified name and disables all other titled sheets. Sheets without a title stay enabled (persistent styles).

💡
Legacy theme switch (if supported)

1) Feature-detect the method
2) document.enableStyleSheetsForSet("Some style sheet set name") (MDN)
3) New apps: toggle data-theme / CSS classes instead

Related tutorials: selectedStyleSheetSet, styleSheetSets, lastStyleSheetSet.

Understanding document.enableStyleSheetsForSet()

An instance method on Document from the legacy style sheet set API (MDN).

  • name — title of the set to enable (MDN).
  • Effect — matching titles enabled; other titled sheets disabled (MDN).
  • Untitled sheets — never affected; always stay enabled (MDN).
  • Empty string — disables alternate and preferred sheets; keeps persistent untitled sheets (MDN).
  • null — no effect; use "" instead (MDN Notes).
  • Case — title matches are case-sensitive (MDN Notes).
  • Side effects — does not change lastStyleSheetSet or preferredStyleSheetSet (MDN Notes).
  • Return valueundefined (MDN).

📝 Syntax

General form of Document.enableStyleSheetsForSet (MDN):

JavaScript
enableStyleSheetsForSet(name)

Parameters

  • name — the name of the style sheets to enable (MDN). Matching titles are enabled; other titled sheets are disabled. Pass "" to disable alternate and preferred sheets (not persistent untitled ones).

Return value

None (undefined) (MDN).

Exceptions

None highlighted on MDN. Calling a missing method throws TypeError — feature-detect first.

MDN example

JavaScript
document.enableStyleSheetsForSet("Some style sheet set name");

⚡ Quick Reference

GoalCode
Feature-detecttypeof document.enableStyleSheetsForSet === "function"
Enable a set (legacy)document.enableStyleSheetsForSet("Dark")
Disable alternate/preferreddocument.enableStyleSheetsForSet("")
null behaviorNo effect (MDN) — use ""
Modern themedocument.documentElement.dataset.theme = "dark"
MDN statusDeprecated & Non-standard

🔍 At a Glance

Four facts about document.enableStyleSheetsForSet().

Returns
undefined

MDN

Arg
name

title match

Prefer
data-theme

modern

Status
Deprecated

+ Non-standard

📋 "" vs null vs a real name

ArgumentEffect (MDN)
"Some set"Enable matching titles; disable other titled sheets
""Disable alternate and preferred sheets; keep persistent untitled sheets
nullNo effect

Examples Gallery

Examples follow MDN Document: enableStyleSheetsForSet() with safe feature detection. On many modern browsers the method is missing — that is expected.

📚 Getting Started

Detect the legacy API before you call it.

Example 1 — Feature-detect enableStyleSheetsForSet

Never assume the method exists.

JavaScript
const supported = typeof document.enableStyleSheetsForSet === "function";
console.log(supported ? "legacy API available" : "enableStyleSheetsForSet missing");

if (!supported) {
  console.log("Prefer data-theme / CSS class themes instead.");
}
Try It Yourself

How It Works

Checking typeof avoids a TypeError when engines removed the alternate stylesheet set helpers.

Example 2 — MDN: enable a named set

Guarded version of MDN’s one-liner.

JavaScript
if (typeof document.enableStyleSheetsForSet === "function") {
  document.enableStyleSheetsForSet("Some style sheet set name");
  console.log("called enableStyleSheetsForSet");
} else {
  console.log("API not available");
}
Try It Yourself

How It Works

When supported, sheets whose title matches the name are enabled and other titled sheets are disabled (MDN). Title matching is case-sensitive.

📈 Practical Patterns

Empty string, null rules, and a modern replacement.

Example 3 — Empty string disables alternate/preferred (MDN)

Pass "" — not null — to clear alternate sets.

JavaScript
if (typeof document.enableStyleSheetsForSet !== "function") {
  console.log("skipped — API missing");
} else {
  document.enableStyleSheetsForSet("");
  console.log("disabled alternate/preferred sets");
}
Try It Yourself

How It Works

MDN: empty string disables alternate and preferred stylesheets but keeps persistent sheets that have no title.

Example 4 — null has no effect (MDN Notes)

Do not use null when you mean “turn sets off.”

JavaScript
if (typeof document.enableStyleSheetsForSet !== "function") {
  console.log("API missing — remember: null ≠ empty string");
} else {
  document.enableStyleSheetsForSet(null); // no effect (MDN)
  console.log("null call completed with no effect");
}
Try It Yourself

How It Works

MDN Notes: null does nothing. Use "" to disable alternate/preferred sheets.

Example 5 — Modern replacement: data-theme

App-controlled themes work everywhere without the legacy set API.

JavaScript
function setTheme(name) {
  document.documentElement.dataset.theme = name;
}

setTheme("dark");
console.log(document.documentElement.dataset.theme); // "dark"

// CSS:
// :root[data-theme="dark"] { color-scheme: dark; background: #111; color: #eee; }
Try It Yourself

How It Works

You own the theme names in your CSS. No titled alternate <link> sets, no missing Document methods.

🚀 Common Use Cases

  • Reading legacy samples — understand old alternate stylesheet demos.
  • Migrating theme pickers — replace with class / data-theme toggles.
  • Interview trivia — know it is deprecated, non-standard, and not in a spec.
  • Not for new apps — prefer CSS themes and prefers-color-scheme.
  • Paired APIs — often appears with selectedStyleSheetSet / styleSheetSets.
  • Remember — it does not update lastStyleSheetSet (MDN Notes).

🧠 How enableStyleSheetsForSet() Worked

1

Pass a set name

A string matching stylesheet title values (case-sensitive).

Input
2

Enable matching titles

MDN: sheets with that title turn on.

Enable
3

Disable other titled sheets

Untitled (persistent) sheets stay enabled (MDN).

Disable
4

Migrate to modern themes

Use data-theme, CSS variables, or media queries in new products.

📝 Notes

  • MDN: Deprecated and Non-standard; not part of any specification.
  • Title matches are case-sensitive (MDN Notes).
  • null has no effect; use "" to disable alternate/preferred sheets (MDN Notes).
  • Untitled stylesheets are never affected (MDN Notes).
  • Does not change lastStyleSheetSet or preferredStyleSheetSet (MDN Notes).
  • Related: selectedStyleSheetSet, styleSheetSets, lastStyleSheetSet.

Limited / Legacy Browser Support

Document.enableStyleSheetsForSet() is Deprecated and Non-standard on MDN (not part of any specification). Logos use the shared browser-image-sprite.png sprite from this project. Do not ship new features that depend on it.

Deprecated · Non-standard

Document.enableStyleSheetsForSet()

Legacy alternate stylesheet set switcher — missing in many current browsers. Prefer data-theme / CSS themes.

Legacy Not for new apps
Google Chrome Legacy / omitted in modern versions — avoid
Avoid
Mozilla Firefox Legacy path; do not depend on it for new code
Avoid
Apple Safari Treat as unavailable for new products
Avoid
Microsoft Edge Chromium Edge: treat as unavailable for new code
Avoid
Opera Follow Chromium legacy status
Avoid
Internet Explorer No practical modern path
Unavailable
enableStyleSheetsForSet() Avoid

Bottom line: Feature-detect if you must read legacy code. For new work, toggle themes with CSS classes, data attributes, or prefers-color-scheme.

Conclusion

document.enableStyleSheetsForSet(name) was a legacy way to flip alternate stylesheet titles on and off. MDN marks it deprecated and non-standard. Feature-detect if you must read old samples, remember "" vs null, and migrate themes to CSS you control.

Continue with elementsFromPoint(), evaluate(), or the JavaScript hub.

💡 Best Practices

✅ Do

  • Treat this as historical / migration knowledge
  • Feature-detect before calling
  • Use "" (not null) to clear alternate/preferred sets (MDN)
  • Build themes with data-theme or CSS classes
  • Also learn selectedStyleSheetSet for legacy audits

❌ Don’t

  • Use this API in new production code (MDN)
  • Pass null expecting a disable-all effect (MDN)
  • Expect lastStyleSheetSet to update (MDN Notes)
  • Assume titled sheet matching is case-insensitive
  • Depend on browser UI for alternate stylesheet menus

Key Takeaways

Knowledge Unlocked

Five things to remember about enableStyleSheetsForSet()

Legacy stylesheet-set switcher — deprecated and non-standard.

5
Core concepts
⚠️02

Status

Deprecated

MDN
🛡03

Also

Non-standard

MDN
📄04

Clear

use ""

not null
💡05

Prefer

data-theme

modern

❓ Frequently Asked Questions

MDN: it enables the style sheets matching the specified name in the current style sheet set, and disables all other style sheets (except those without a title, which are always enabled).
Yes. MDN marks Document.enableStyleSheetsForSet() as Deprecated and Non-standard. It is not part of any specification.
MDN: the name of the style sheets to enable. All style sheets with a matching title are enabled; other titled sheets are disabled. Pass "" to disable all alternate and preferred sheets (persistent untitled sheets stay enabled).
No. MDN: calling with a null name has no effect. To disable alternate/preferred sheets you must pass the empty string "".
No. MDN Notes: this method never affects document.lastStyleSheetSet or document.preferredStyleSheetSet.
Prefer modern theming: toggle a class or data-theme on document.documentElement, CSS custom properties, prefers-color-scheme, or adoptedStyleSheets. Do not build new apps on the alternate stylesheet set API.
Did you know?

Persistent stylesheets are the ones with no title. Preferred and alternate sheets use titles (and often rel="stylesheet" vs rel="alternate stylesheet"). enableStyleSheetsForSet only flips the titled groups — untitled sheets keep applying (MDN).

Next: evaluate()

Learn how to run XPath expressions with document.evaluate() and read XPathResult.

evaluate() →

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.

7 people found this page helpful