JavaScript Document styleSheets Property

Beginner
⏱️ 12 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Baseline Widely available
Instance property

What You’ll Learn

Document.styleSheets is a read-only instance property that returns every CSS stylesheet linked or embedded in the document. Learn how to count sheets, find one by title, read cssRules, compare with adoptedStyleSheets, and five examples with try-it labs.

01

Kind

Read-only property

02

Returns

StyleSheetList

03

Items

CSSStyleSheet

04

Sources

link + style

05

Rules

cssRules

06

Status

Baseline widely

Introduction

Every styled page loads CSS from <link rel="stylesheet"> tags, inline <style> blocks, and sometimes HTTP Link headers. When JavaScript needs to inspect those stylesheets programmatically, document.styleSheets is the standard entry point.

MDN: the styleSheets read-only property returns a StyleSheetList of CSSStyleSheet objects, for stylesheets explicitly linked into or embedded in a document.

💡
CSSOM, not the DOM tree

styleSheets is a CSS Object Model (CSSOM) list. It complements DOM collections like links (which returns <link> elements) by exposing live stylesheet objects with cssRules.

Related Document tutorials: adoptedStyleSheets, links, scripts, Document constructor.

Understanding Document.styleSheets

A read-only instance property from the CSS Object Model.

  • ValueStyleSheetList of CSSStyleSheet items (MDN).
  • Includes — linked external sheets and embedded <style> blocks.
  • Order — Link-header sheets first, then DOM sheets in tree order (MDN).
  • Accesslength, index, or for...of loop.
  • Status — Baseline Widely available (since July 2015, MDN).

📝 Syntax

JavaScript
document.styleSheets

Value

A StyleSheetList of CSSStyleSheet objects (MDN).

MDN: find sheet by title

JavaScript
function getStyleSheet(uniqueTitle) {
  for (const sheet of document.styleSheets) {
    if (sheet.title === uniqueTitle) {
      return sheet;
    }
  }
}

⚡ Quick Reference

GoalCode / note
Get listdocument.styleSheets
Count sheetsdocument.styleSheets.length
First sheetdocument.styleSheets[0]
External URLsheet.href (null if inline)
Find by titleLoop and match sheet.title (MDN)
Read rulessheet.cssRules (same-origin only)

🔍 At a Glance

Four facts about document.styleSheets.

Type
StyleSheetList

Read-only

Items
CSSStyleSheet

CSSOM

Order
header+DOM

MDN

Status
Baseline

Since 2015

📋 styleSheets vs adoptedStyleSheets

styleSheetsadoptedStyleSheets
SourceLinked / embedded in markupConstructable sheets from JS
Mutable arrayRead-only listYes (assign array)
Typical useInspect page CSSInject dynamic CSS at runtime
MDN statusBaseline Widely availableBaseline (constructable API)

Examples Gallery

Examples follow MDN Document: styleSheets. Each includes a try-it lab you can run in the browser.

📚 Getting Started

Count and list stylesheets on a page.

Example 1 — Count Stylesheets

Use length to see how many sheets the document exposes.

JavaScript
const count = document.styleSheets.length;
console.log("Stylesheet count:", count);
Try It Yourself

How It Works

Includes both external linked CSS and inline <style> blocks.

Example 2 — List Sheet URLs or “inline”

Loop the list and show each sheet’s href.

JavaScript
for (const sheet of document.styleSheets) {
  console.log(sheet.href || "inline");
}
Try It Yourself

How It Works

Inline sheets have href === null; external sheets return the full URL string.

📈 MDN Patterns & CSS Rules

Find sheets by title and read selector names.

Example 3 — Find Stylesheet by Title (MDN)

MDN helper to locate a sheet with a matching title attribute.

JavaScript
function getStyleSheet(uniqueTitle) {
  for (const sheet of document.styleSheets) {
    if (sheet.title === uniqueTitle) {
      return sheet;
    }
  }
}

const sheet = getStyleSheet("Main");
console.log(sheet ? "Found Main" : "Not found");
Try It Yourself

How It Works

The title on <link> or <style> becomes sheet.title.

Example 4 — Log Rule Selectors (MDN)

Print each rule’s selectorText from accessible sheets.

JavaScript
for (const styleSheet of document.styleSheets) {
  try {
    for (const rule of styleSheet.cssRules) {
      console.log(rule.selectorText);
    }
  } catch (e) {
    console.log("(cross-origin sheet — cssRules blocked)");
  }
}
Try It Yourself

How It Works

MDN demo output for body, p, and #lumpy rules. Cross-origin sheets need try/catch.

Example 5 — Compare with adoptedStyleSheets

Document sheets vs constructable sheets attached via JavaScript.

JavaScript
console.log({
  styleSheets: document.styleSheets.length,
  adoptedStyleSheets: document.adoptedStyleSheets.length
});
Try It Yourself

How It Works

styleSheets reflects markup; adoptedStyleSheets holds JS-constructed sheets you assign.

🚀 Common Use Cases

  • Debug CSS loading — count how many sheets loaded on a page.
  • Theme inspection — find alternate sheets by title.
  • DevTools-style tools — list selectors from inline CSS safely.
  • Performance audits — inventory external href URLs.
  • Teaching CSSOM — connect DOM <link> to live sheets.
  • Pair with adoptedStyleSheets — compare static vs dynamic CSS.

🧠 How document.styleSheets Works

1

Browser loads CSS

From <link>, <style>, or Link headers.

Parse
2

CSSOM builds StyleSheet objects

Each sheet becomes a CSSStyleSheet with rules.

CSSOM
3

Document exposes styleSheets

Ordered list: header sheets first, then DOM tree order (MDN).

Property
4

Script reads rules and metadata

Use href, title, and cssRules for inspection tools.

📝 Notes

  • MDN: Baseline Widely available (since July 2015) — no Deprecated / Experimental / Non-standard banner.
  • Cross-origin stylesheets block cssRules access (SecurityError) — use try/catch.
  • Order: Link-header sheets first, then DOM sheets in tree order (MDN).
  • Does not include constructable sheets until they appear in the document model appropriately; use adoptedStyleSheets for JS-injected sheets.
  • Related: adoptedStyleSheets, links, Document constructor.

Browser Support

Document.styleSheets is marked Baseline Widely available on MDN (since July 2015). Logos use the shared browser-image-sprite.png sprite from this project.

Baseline · Widely available

Document.styleSheets

Read-only StyleSheetList — linked and embedded CSSStyleSheet objects with cssRules.

Widely Available
Google Chrome Full support · Desktop & Mobile
Full support
Mozilla Firefox Full support · Desktop & Mobile
Full support
Apple Safari Full support · macOS & iOS
Full support
Microsoft Edge Full support · Chromium
Full support
Opera Full support · Modern versions
Full support
Internet Explorer Supported in legacy IE
Full support
Document.styleSheets Baseline support

Bottom line: Use document.styleSheets to inspect page CSS. Wrap cssRules access in try/catch for cross-origin sheets; pair with adoptedStyleSheets for constructable CSS.

Conclusion

Document.styleSheets is the standard CSSOM list of every stylesheet linked or embedded in a document. Count sheets, read href and title, and inspect cssRules on same-origin CSS. For constructable sheets, use adoptedStyleSheets.

Continue with timeline, adoptedStyleSheets, links, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Use document.styleSheets to inventory page CSS
  • Wrap cssRules reads in try/catch
  • Loop with for...of for clarity
  • Check sheet.href to separate inline vs external
  • Use adoptedStyleSheets for dynamic JS CSS

❌ Don’t

  • Assume every sheet exposes cssRules
  • Confuse styleSheets with links DOM list
  • Modify the StyleSheetList directly (read-only)
  • Rely on order without knowing header vs DOM rules
  • Use legacy style sheet set APIs for new themes

Key Takeaways

Knowledge Unlocked

Five things to remember about document.styleSheets

CSSOM list of linked and embedded stylesheets.

5
Core concepts
📄02

Items

CSSStyleSheet

Type
📝03

Rules

cssRules

CSSOM
🔗04

href

URL|null

Meta
05

Status

Baseline

2015+

❓ Frequently Asked Questions

A read-only StyleSheetList of CSSStyleSheet objects for stylesheets explicitly linked into or embedded in the document (MDN).
No. MDN marks Document.styleSheets as Baseline Widely available (since July 2015). It is part of the standard CSS Object Model (CSSOM).
MDN: Link header stylesheets come first (header order), then DOM stylesheets (tree order).
Loop document.styleSheets and compare sheet.title to your target name (MDN example pattern).
Only same-origin stylesheets. Cross-origin sheets may throw a SecurityError when accessing cssRules — wrap in try/catch.
document.styleSheets lists linked and embedded document stylesheets. document.adoptedStyleSheets holds constructable stylesheets you attach via JavaScript.
Did you know?

MDN states the returned list is ordered with Link-header stylesheets first (sorted in header order), then stylesheets from the DOM (sorted in tree order). That is why programmatic order may differ from visual source order in DevTools.

Next: timeline

Learn the document’s default DocumentTimeline for Web Animations.

timeline →

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