JavaScript Document enableStyleSheetsForSet() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Method

Definition

document.enableStyleSheetsForSet(name) enables every stylesheet whose title matches name, and disables other titled sheets. Sheets with no title stay enabled (MDN). Returns undefined.

Pass the required arguments shown below. Check return values and browser support before you rely on the result.

Syntax

Call document.enableStyleSheetsForSet. Start with this line.

JavaScript
document.enableStyleSheetsForSet(name)
CallWhat it does
document.enableStyleSheetsForSet(name)Primary signature.
document.enableStyleSheetsForSet(...)Call with the arguments your case needs.

Built into the browser. Call enableStyleSheetsForSet(...) on document — no import required.

Library declarations
JavaScript
document.enableStyleSheetsForSet(name)

Parameters

ParameterDescription
nameRequired. Title to enable; "" disables titled alternates

Return Value

Return ValueDescription
*Always undefined

JavaScript Examples

Example 1 — Feature-Detect

Check for a function before calling this legacy method.

JavaScript
const ok = typeof document.enableStyleSheetsForSet === "function";

console.log(ok ? "legacy API available" : "missing — use modern themes");
Try It Yourself

How It Works

  1. Read typeof. Look for "function".
  2. Branch safely. Skip the call when the method is missing.
  3. Plan a modern path. Themes should not depend on this API.
  4. Literacy only. Useful to recognize old code, not to ship new features.

Example 2 — Call If Present

MDN call shape: pass the stylesheet set name when supported.

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

How It Works

  1. Guard the call. Avoid throwing on missing methods.
  2. Pass a set name. Matching title sheets turn on (MDN).
  3. Other titled sheets disable. Untitled sheets stay on.
  4. Return is unused. The method returns undefined.

Example 3 — Empty String vs null

MDN: use "" to disable alternate/preferred sheets; null does nothing.

JavaScript
if (typeof document.enableStyleSheetsForSet !== "function") {
  console.log("skip");
} else {
  document.enableStyleSheetsForSet(null); // no effect
  document.enableStyleSheetsForSet("");   // disable titled alternates
  console.log("empty string applied");
}
Try It Yourself

How It Works

  1. Detect first. Exit early when unsupported.
  2. null is a no-op. MDN documents this explicitly.
  3. Pass "". Disables alternate/preferred titled sheets.
  4. Persistent sheets remain. Untitled stylesheets stay enabled.

Browser Support

Document.enableStyleSheetsForSet() is Deprecated and Non-standard on MDN. It is not part of any specification. Do not rely on it in new code.

✓ Deprecated · Non-standard

Document.enableStyleSheetsForSet()

Legacy alternate-stylesheet helper. Feature-detect if you must inspect old pages; ship modern theming instead.

Legacy Deprecated API
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
document.enableStyleSheetsForSet() Avoid

Bottom line: Literacy only. Prefer data-theme / class toggles or adoptedStyleSheets for production themes.

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.

Next: evaluate()

Learn how to run XPath expressions against the document.

evaluate() 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