← Chrome 159 reference · All APIs

v159 · cssom · enabled by default

CSSImportRule.styleSheet

CSSImportRule.styleSheet is now nullable in Chromium and returns null whenever an @import rule has no associated stylesheet — notably when its supports(...) import condition evaluates to false. This aligns Chromium with CSSOM, CSS Cascade 5, Firefox, and WebKit, and requires callers inspecting conditional @import rules to guard against null before accessing styleSheet.cssRules or other CSSStyleSheet properties.

Newly converging across engines — nullable styleSheet on false supports() has no BCD subfeature yet (base @import is Baseline Widely available)

  • Chrome · 159 (desktop, Android, WebView)
  • Edge · Chromium-based (inherits 159; no BCD subfeature yet)
  • Firefox · Shipped (Bugzilla 1427715)
  • Safari · WebKit IDL nullable since March 2025 (PR #42784; exact Safari version unrecorded in BCD)

The base import (@import) web-feature is Baseline Widely available since 2018-01-29 per webstatus.dev, and BCD api/CSSImportRule.json records base styleSheet support since Chrome 1 / Edge 12 / Firefox 1 / Safari 1. However, neither BCD nor MDN’s CSSImportRule.styleSheet article (which still states “An @import at-rule always has an associated stylesheet” as of 2026-11-24) tracks nullable styleSheet behavior yet.

at a glance

Shipped inChrome 159 (desktop, Android, Android WebView), enabled by default — filed under “Enabled by default” in the milestone=159 listing; iOS listed as unconfirmed (null) in the ChromeStatus API record
Origin trial / flagNo origin trial, no user-facing chrome://flags toggle. Enabled by default via Blink runtime / Finch flag CSSImportRuleStyleSheetNullable (status: "stable" in runtime_enabled_features.json5)
SpecificationCSSOM §6.4.4 The CSSImportRule Interface; CSS Cascading and Inheritance Level 5 §2.1 Conditional @import Rules
Intentblink-dev Intent to Ship
Tracking bug & CLissues.chromium.org/40266154; Chromium CL 5065830
Web platform testswpt.fyi css/cssom/cssimportrule.html (WPT source)
ChromeStatus5123480866783232 — CSSImportRule.styleSheet

why it exists

CSS Cascade 5 allows @import rules to carry a supports(...) feature-query condition so browsers skip fetching fallback stylesheets on engines that already support newer features. Both CSSOM and CSS Cascade 5 require CSSImportRule.styleSheet to be nullable (CSSStyleSheet?) and to return null when no stylesheet is associated — specifically including when a supports() condition evaluates to false. Before Chrome 159, Blink exposed a non-null CSSStyleSheet object even when the supports() condition did not match, making it impossible to distinguish an active imported stylesheet from a skipped conditional import via rule.styleSheet and diverging from Firefox and WebKit. Chrome 159 aligns Chromium with both specifications.

Source: ChromeStatus summary & motivation (5123480866783232); CSS Cascade 5 §2.1.

Syntax and interface contract

The normative WebIDL for CSSImportRule in CSSOM §6.4.4 declares styleSheet as a nullable read-only attribute returning CSSStyleSheet?:

[Exposed=Window]
interface CSSImportRule : CSSRule {
  readonly attribute USVString href;
  [SameObject, PutForwards=mediaText] readonly attribute MediaList media;
  [SameObject] readonly attribute CSSStyleSheet? styleSheet;
  readonly attribute CSSOMString? layerName;
  readonly attribute CSSOMString? supportsText;
};

/* CSS Cascade 5 — conditional @import syntax */
@import [ <url> | <string> ]
        [ layer | layer(<layer-name>) ]?
        [ supports([ <supports-condition> | <declaration> ]) ]?
        <media-query-list>?;

“The styleSheet attribute must return the associated CSS style sheet, if any, or null otherwise.”

“Additionally, if a <supports-condition> blocks the application of the imported style sheet, the UA must not fetch the style sheet (unless it is loaded through some other link) and must return null for the import rule’s CSSImportRule.styleSheet value (even if it is loaded through some other link).”

This reference covers three parts of the contract: the nullable CSSImportRule.styleSheet getter, conditional @import supports() evaluation and lifecycle, and companion CSSImportRule attributes.

Source: CSSOM §6.4.4 (normative quote fetched 2026-11-24); CSS Cascade 5 §2.1 (normative quote fetched 2026-11-24).

CSSImportRule.styleSheet — inputs and outputs

Inputs. Accessed as a zero-argument read-only getter (rule.styleSheet) on any CSSImportRule instance obtained from sheet.cssRules (where rule instanceof CSSImportRule and rule.type === CSSRule.IMPORT_RULE). Because the attribute is read-only, attempting to assign rule.styleSheet = ... fails silently in sloppy mode and throws a TypeError in strict mode.

Outputs. Returns either a CSSStyleSheet object (annotated [SameObject] when present, so repeated reads return the same wrapper identity) or null when the @import rule has no associated stylesheet:

Return value of CSSImportRule.styleSheet by @import condition state (from CSSOM §6.4.4, CSS Cascade 5 §2.1, and WPT cssimportrule.html)
@import rule conditionNetwork fetchrule.styleSheet in Chrome 159+
Unconditional @import url("a.css");FetchedCSSStyleSheet instance
@import url("a.css") supports(display: flex); (true condition)FetchedCSSStyleSheet instance
@import url("a.css") supports(not (display: flex)); (false condition)Must not fetch (unless loaded elsewhere)null (even if a.css is loaded via another link or rule)
@import rule with no associated stylesheetNonenull
Source: CSSOM §6.4.4; CSS Cascade 5 §2.1; WPT css/cssom/cssimportrule.html.

Conditional @import supports() evaluation and lifecycle

Inputs & outputs. When a stylesheet parses an @import rule carrying supports(<supports-condition> | <declaration>) (a bare declaration such as supports(display: flex) is interpreted as a <supports-decl>), the browser evaluates the supports condition statically against its own CSS feature support:

Lifecycle. Feature support conditions are invariant for a given browser session, so an @import blocked by a false supports() condition stays null for the lifetime of that CSSImportRule. Unlike <media-query-list> conditions (which can change dynamically as the viewport or print mode changes), a false supports() condition never transitions to a loaded stylesheet without replacing the rule.

Source: CSS Cascade 5 §2 & §2.1; WPT css/cssom/cssimportrule.html.

Companion CSSImportRule members

Even when rule.styleSheet is null, the CSSImportRule object itself remains inspectable through its other CSSOM properties:

Companion attributes on CSSImportRule (CSSOM §6.4.4)
AttributeTypeBehavior
hrefUSVString (read-only)Returns the raw URL string as specified in the @import rule (not the resolved URL).
mediaMediaList ([SameObject, PutForwards=mediaText])Returns the rule’s MediaList; assigning a string forwards to media.mediaText.
layerNameCSSOMString? (read-only)Returns the declared layer name, "" for an anonymous layer, or null if no layer was declared.
supportsTextCSSOMString? (read-only)Returns the serialized <supports-condition> text (e.g. "(display: flex) or (display: block)"), or null if no supports() clause is present.
cssTextCSSOMString (inherited from CSSRule)Returns the serialized @import rule string.
Source: CSSOM §6.4.4 The CSSImportRule Interface; WPT css/cssom/cssimportrule.html.

Errors, migration risks, and recovery

Accessing rule.styleSheet itself does not throw an exception. However, ChromeStatus explicitly flags a real migration hazard for Chromium-only code and CSS tooling:

Source: ChromeStatus interop_compat_risks & webview_risks (5123480866783232); CSSOM §6.4.4.

Context and exposure

CSSImportRule is exposed only in Window contexts ([Exposed=Window] in CSSOM WebIDL), not in Web Workers or Worklets. Reading rule.styleSheet requires no secure context, permission, or user activation; it operates on any accessible CSSStyleSheet (including <style> elements, same-origin <link rel="stylesheet"> sheets, and shadow root stylesheets).

Source: CSSOM §6.4.4 ([Exposed=Window]).

Examples

No interactive demo exists yet on the Chrome Platform Showcase for Chrome 159 (checked 2026-11-24).

Checking CSSImportRule.styleSheet for conditional @import supports() rules

<style id="conditional-imports">
  @import url("modern-grid.css") supports(display: flex);
  @import url("legacy-fallback.css") supports(not (display: flex));
</style>

<script>
  const { cssRules } = document.getElementById("conditional-imports").sheet;

  for (const rule of cssRules) {
    if (!(rule instanceof CSSImportRule)) continue;

    if (rule.styleSheet === null) {
      // Condition did not match (e.g. supports(not (display: flex)) on modern browsers):
      // stylesheet was not fetched and has no associated CSSStyleSheet,
      // while href, supportsText, layerName, and media remain inspectable.
      console.log(
        `Skipped @import ${rule.href}`,
        { supports: rule.supportsText, layer: rule.layerName, media: rule.media.mediaText }
      );
      continue;
    }

    console.log(`Loaded @import ${rule.href}:`, rule.styleSheet);
  }
</script>
Source: WPT css/cssom/cssimportrule.html; CSS Cascade 5 §2.1.

Null-safe and CORS-safe recursive stylesheet walker

function collectActiveStyleSheets(rootSheet, visited = new Set()) {
  if (!rootSheet || visited.has(rootSheet)) return visited;
  visited.add(rootSheet);

  let rules;
  try {
    rules = rootSheet.cssRules;
  } catch (err) {
    // Cross-origin stylesheet without CORS headers throws SecurityError.
    return visited;
  }

  for (const rule of rules) {
    if (rule instanceof CSSImportRule && rule.styleSheet !== null) {
      collectActiveStyleSheets(rule.styleSheet, visited);
    }
  }
  return visited;
}
Source: CSSOM §6.4.4; ChromeStatus compatibility guidance (5123480866783232).

Browser compatibility

Support for nullable CSSImportRule.styleSheet (returning null when an @import has no associated stylesheet, including false supports()). BCD api/CSSImportRule.json tracks only base styleSheet support; nullable status comes from ChromeStatus, Bugzilla 1427715, WebKit PR #42784, and wpt.fyi (checked 2026-11-24).
BrowserNullable styleSheetEvidence / notesBase CSSImportRule.styleSheet (BCD)
Chrome (desktop, Android, WebView)159Enabled by default via CSSImportRuleStyleSheetNullable (CL 5065830) per ChromeStatus API record; Chrome on iOS listed as null (unconfirmed)1
EdgeUnknown
(Chromium 159)
Chromium-based; inherits Chromium 159 behavior (no separate BCD subfeature)12
FirefoxShippedAlready supports nullable CSSImportRule.styleSheet per Bugzilla 1427715#c12 and ChromeStatus (exact subfeature version not recorded in BCD)1
SafariShipped
(version unknown)
WebKit PR #42784 (merged 2025-03-24) made CSSImportRule.styleSheet nullable in WebKit IDL; exact stable Safari release version not yet recorded in BCD1
Source: BCD api/CSSImportRule.json; ChromeStatus API record (5123480866783232); wpt.fyi cssimportrule.html; webstatus.dev import.

Security and privacy

Returning null from CSSImportRule.styleSheet when a supports() condition is false reduces unnecessary network fetches and avoids synthesizing a placeholder CSSStyleSheet object for a stylesheet that was never loaded. CSS Cascade 5 §2.1 further specifies that styleSheet must remain null even if the same URL was loaded elsewhere in the document, preventing a blocked conditional import from exposing another link’s stylesheet handle. Cross-origin CSSStyleSheet.cssRules origin restrictions remain unchanged whenever styleSheet is non-null. ChromeStatus notes no new security risks and lists security/privacy reviews as Pending (checked 2026-11-24).

Source: CSS Cascade 5 §2.1; ChromeStatus security_risks & review status (5123480866783232).

Specifications

see also