JavaScript Document lastStyleSheetSet Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Property

Definition

Document.lastStyleSheetSet returns the last enabled style sheet set name. Its value updates when document.selectedStyleSheetSet changes (MDN).

Read the notes below before you get or set this property. Prefer feature detection when support is limited.

Syntax

Use document.lastStyleSheetSet. Start with this line.

JavaScript
document.lastStyleSheetSet
CallWhat it does
document.lastStyleSheetSetPrimary signature.

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

Library declarations
JavaScript
document.lastStyleSheetSet

Parameters

ParameterDescription
Feature detectRequired. Many browsers omit this API

Return Value

Return ValueDescription
*The current value of document.lastStyleSheetSet.

JavaScript Examples

Example 1 — Feature Detect

Check whether this browser exposes the legacy property at all.

JavaScript
const supported = "lastStyleSheetSet" in document;

console.log("lastStyleSheetSet supported?", supported);
Try It Yourself

How It Works

  1. Use the in operator. Tests for the property on document.
  2. Expect false often. Many engines never shipped (or removed) style sheet sets.
  3. Guard first. Never assume the property exists before reading it.
  4. Legacy only. Support is not a reason to adopt this API in new apps.

Example 2 — Safe Read (MDN Pattern)

Read the last set name, with MDN’s fallback when it is still null.

JavaScript
let lastSheetSet = "lastStyleSheetSet" in document
  ? document.lastStyleSheetSet
  : null;

if (!lastSheetSet) {
  lastSheetSet = "Style sheet not yet changed";
}

console.log(lastSheetSet);
Try It Yourself

How It Works

  1. Detect, then read. Missing API → treat as null.
  2. MDN null case. Never assigning selectedStyleSheetSet leaves lastStyleSheetSet as null.
  3. Friendly message. Replace null/missing with a clear string for demos.
  4. Still legacy. Useful for reading old code, not for shipping themes.

Example 3 — Modern Theme Alternative

Toggle a class on the document root instead of using style sheet sets.

JavaScript
document.documentElement.classList.toggle("dark");

const isDark = document.documentElement.classList.contains("dark");
console.log("theme:", isDark ? "dark" : "light");
Try It Yourself

How It Works

  1. Target the root. document.documentElement is usually <html>.
  2. Toggle a class. CSS (or later styles) can key off .dark.
  3. Read the state. classList.contains reports the current theme.
  4. Why this wins. Standard, widely supported, and easy to persist—unlike style sheet sets.

Browser Support

Document.lastStyleSheetSet is Deprecated and Non-standard on MDN. Support is limited and unreliable across modern browsers.

✓ Deprecated · Non-standard

Document.lastStyleSheetSet

Legacy last enabled style sheet set name — null until selectedStyleSheetSet changes; often unavailable.

Low Legacy / limited
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
lastStyleSheetSet Avoid

Bottom line: Do not build new theme UIs on this API. Feature-detect if you must read legacy pages. Prefer documentElement class toggles, CSS, matchMedia, or adoptedStyleSheets.

Frequently Asked Questions

The last enabled style sheet set name. The value changes when document.selectedStyleSheetSet is changed. If selectedStyleSheetSet has never been set, the value is null (MDN).
Yes. MDN marks Document.lastStyleSheetSet as Deprecated and Non-standard. Do not use it in new projects.
No. MDN notes that this value does not change when document.enableStyleSheetsForSet() is called — only when selectedStyleSheetSet is changed.
If the selected set was never changed via selectedStyleSheetSet, MDN says the value is null. Many modern browsers also never implemented (or removed) the alternate style sheet set API.
Prefer toggling a class on document.documentElement, CSS custom properties, prefers-color-scheme via matchMedia, or adoptedStyleSheets.
Only to understand legacy code. New theme switching should use CSS and standard DOM APIs, not style sheet sets.

Next: preferredStyleSheetSet

Learn the legacy preferred style sheet set property next.

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

8 people found this page helpful