JavaScript Document lastStyleSheetSet Property

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

What You’ll Learn

Document.lastStyleSheetSet is a deprecated, non-standard instance property that returns the last enabled style sheet set name. Learn how it relates to selectedStyleSheetSet, when it is null, how to feature-detect it, and what to use instead for themes.

01

Kind

Instance property

02

Returns

string | null

03

Status

Deprecated

04

Also

Non-standard

05

Updates on

selectedStyleSheetSet

06

Prefer

CSS themes

Introduction

Years ago, HTML offered alternate stylesheets with <link rel="stylesheet" title="..."> and rel="alternate stylesheet". Browsers could switch among named “style sheet sets.” Document APIs like selectedStyleSheetSet and lastStyleSheetSet exposed that switching.

MDN: lastStyleSheetSet returns the last enabled style sheet set. Its value changes whenever document.selectedStyleSheetSet is changed. If the current set has never been changed that way, the value is null.

💡
Modern replacement

Today, theme UIs almost always toggle classes or CSS variables on <html> / <body>. That approach works everywhere and does not depend on this legacy API.

Related Document tutorials: adoptedStyleSheets, documentElement, Document constructor.

Understanding Document.lastStyleSheetSet

An instance property from the legacy style sheet set API.

  • Value — name of the last enabled set, or null if selectedStyleSheetSet was never changed (MDN).
  • Updates — when document.selectedStyleSheetSet changes (MDN).
  • Does not update — when document.enableStyleSheetsForSet() is called (MDN).
  • Status — Deprecated and Non-standard (MDN).
  • Support — often missing; always feature-detect.

📝 Syntax

JavaScript
document.lastStyleSheetSet

Value

A string naming the style sheet set most recently set, or null if selectedStyleSheetSet has not been changed (MDN).

MDN example

JavaScript
let lastSheetSet = document.lastStyleSheetSet;

if (!lastSheetSet) {
  lastSheetSet = "Style sheet not yet changed";
} else {
  console.log(`The last style sheet set is: ${lastSheetSet}`);
}

⚡ Quick Reference

GoalCode / note
Feature-detect"lastStyleSheetSet" in document
Read last setdocument.lastStyleSheetSet
Null meaningSet never changed via selectedStyleSheetSet (MDN)
Modern themedocument.documentElement.classList.toggle("dark")
MDN statusDeprecated & Non-standard

🔍 At a Glance

Four facts about document.lastStyleSheetSet.

Type
string | null

Set name

Status
deprecated

Avoid

Also
non-standard

Limited

Prefer
CSS class

Themes

📋 Legacy Sets vs Class Themes

Style sheet setsClass / CSS variables
Portable?No (MDN: non-standard)Yes
Recommended?No (deprecated)Yes
Typical APIlastStyleSheetSetclassList / :root
Beginner tipRead only for legacyUse for new themes

Examples Gallery

Examples follow MDN Document: lastStyleSheetSet. 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 lastStyleSheetSet

Never assume the property exists.

JavaScript
const supported = "lastStyleSheetSet" in document;
console.log("lastStyleSheetSet 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 ("lastStyleSheetSet" in document) {
  console.log(document.lastStyleSheetSet);
} else {
  console.log("Property not available in this browser");
}
Try It Yourself

How It Works

When supported and never changed via selectedStyleSheetSet, MDN says the value is null.

📈 MDN Pattern, selectedStyleSheetSet & Modern Themes

Legacy behavior notes and the recommended replacement.

Example 3 — MDN: Fallback Message When Null

Treat a missing or null set as “not yet changed.”

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

if (!lastSheetSet) {
  lastSheetSet = "Style sheet not yet changed";
} else {
  console.log(`The last style sheet set is: ${lastSheetSet}`);
}

console.log(lastSheetSet);
Try It Yourself

How It Works

Adapted from MDN so unsupported browsers still show a clear message.

Example 4 — Relationship to selectedStyleSheetSet

MDN: lastStyleSheetSet updates when the selected set changes.

JavaScript
function reportStyleSheetSets() {
  if (!("lastStyleSheetSet" in document)) {
    return "Style sheet set API not supported";
  }
  return {
    selected: document.selectedStyleSheetSet,
    last: document.lastStyleSheetSet
  };
}

console.log(reportStyleSheetSets());
Try It Yourself

How It Works

Calling enableStyleSheetsForSet() alone does not update lastStyleSheetSet (MDN).

Example 5 — Prefer a Modern Theme Toggle

Use a root class instead of style sheet sets.

JavaScript
function toggleTheme() {
  document.documentElement.classList.toggle("dark");
  const isDark = document.documentElement.classList.contains("dark");
  console.log("theme:", isDark ? "dark" : "light");
}

toggleTheme();
Try It Yourself

How It Works

Pair with CSS like :root.dark { color-scheme: dark; ... } for portable theming.

🚀 Common Use Cases

  • Legacy migration — find old alternate-stylesheet switchers.
  • Feature detection — decide whether a polyfill/UI path is needed.
  • Debugging old Firefox UIs — inspect last selected set where still present.
  • Teaching history — compare style sheet sets with modern theme classes.
  • Do not use for new themes — prefer CSS / classList.
  • Docs / audits — flag deprecated API usage in code reviews.

🧠 How the Legacy Set Flow Worked

1

Page declares alternate stylesheets

Named <link> stylesheets with titles formed style sheet sets.

Markup
2

Script sets selectedStyleSheetSet

That assignment updates lastStyleSheetSet (MDN).

Select
3

You read lastStyleSheetSet

Returns the last enabled set name, or null if never changed.

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.
  • Updates when selectedStyleSheetSet changes; not when enableStyleSheetsForSet() is called (MDN).
  • Often unavailable in Chromium and other modern engines.
  • Prefer class-based themes or adoptedStyleSheets for new work.
  • Related: adoptedStyleSheets, lastModified, documentElement, Document constructor.

Browser Support

Document.lastStyleSheetSet 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.lastStyleSheetSet

Legacy style sheet set name — last enabled set after selectedStyleSheetSet changes.

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.lastStyleSheetSet 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.lastStyleSheetSet remembers the last style sheet set enabled via selectedStyleSheetSet. 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 preferredStyleSheetSet, ownerDocument, adoptedStyleSheets, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Feature-detect before reading lastStyleSheetSet
  • Use class toggles / CSS variables for themes
  • Prefer adoptedStyleSheets for constructable CSS
  • Respect prefers-color-scheme when possible
  • Migrate legacy alternate-stylesheet UIs when you find them

❌ Don’t

  • Build new products on style sheet set APIs
  • Assume Chromium exposes lastStyleSheetSet
  • Expect enableStyleSheetsForSet to update this property
  • Skip null checks even in supporting browsers
  • Confuse this with document.styleSheets (live stylesheet list)

Key Takeaways

Knowledge Unlocked

Five things to remember about document.lastStyleSheetSet

A legacy style sheet set name — not for new code.

5
Core concepts
⚠️02

Status

Deprecated

MDN
🚫03

Also

Non-standard

Avoid
🔄04

Updates

selectedStyleSheetSet

MDN
🎨05

Prefer

CSS themes

Modern

❓ 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 code.
No. MDN notes that this value does not change when document.enableStyleSheetsForSet() is called — only when selectedStyleSheetSet is changed.
Many modern browsers never implemented (or already removed) the alternate style sheet set API. Feature-detect before reading the property.
Prefer toggling a class on document.documentElement (for example dark), CSS custom properties, prefers-color-scheme, or adoptedStyleSheets for constructable stylesheets.
Only to understand legacy code. New theme switching should use CSS and standard DOM APIs, not style sheet sets.
Did you know?

Firefox once exposed a View → Page Style menu for alternate stylesheets. That UI, together with Document style sheet set properties, is part of why you may still see these names in very old tutorials—even though modern theme systems moved on.

Next: preferredStyleSheetSet

Learn the author’s preferred style sheet set name on Document.

preferredStyleSheetSet →

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