← 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.
at a glance
| Shipped in | Chrome 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 / flag | No origin trial, no user-facing chrome://flags toggle. Enabled by default via Blink runtime / Finch flag CSSImportRuleStyleSheetNullable (status: "stable" in runtime_enabled_features.json5) |
| Specification | CSSOM §6.4.4 The CSSImportRule Interface; CSS Cascading and Inheritance Level 5 §2.1 Conditional @import Rules |
| Intent | blink-dev Intent to Ship |
| Tracking bug & CL | issues.chromium.org/40266154; Chromium CL 5065830 |
| Web platform tests | wpt.fyi css/cssom/cssimportrule.html (WPT source) |
| ChromeStatus | 5123480866783232 — 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.
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
styleSheetattribute 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 returnnullfor the import rule’sCSSImportRule.styleSheetvalue (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.
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:
@import rule condition | Network fetch | rule.styleSheet in Chrome 159+ |
|---|---|---|
Unconditional @import url("a.css"); | Fetched | CSSStyleSheet instance |
@import url("a.css") supports(display: flex); (true condition) | Fetched | CSSStyleSheet 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 stylesheet | None | null |
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:
- Rule still appears in
cssRules: Both matching and non-matching@importrules produce aCSSImportRuleentry inparentStyleSheet.cssRules(verified in WPTcssimportrule.html, where a<style>containing one true and one falsesupports()import producescssRules.length === 2). - No fetch &
nullsheet on false condition: When the supports condition isfalse, the user agent does not fetch the URL for this rule and sets no associated stylesheet, sorule.styleSheet === null. Even if the exact same URL is imported unconditionally elsewhere on the page, this rule’sstyleSheetremainsnull. - Cascade layer ordering: Per CSS Cascade 5 §2, an optional
layerorlayer(<layer-name>)declaration on an@importis subject to the rule’s import conditions (as if wrapped in an@supportsblock).
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.
Companion CSSImportRule members
Even when rule.styleSheet is null, the CSSImportRule object itself remains inspectable through its other CSSOM properties:
| Attribute | Type | Behavior |
|---|---|---|
href | USVString (read-only) | Returns the raw URL string as specified in the @import rule (not the resolved URL). |
media | MediaList ([SameObject, PutForwards=mediaText]) | Returns the rule’s MediaList; assigning a string forwards to media.mediaText. |
layerName | CSSOMString? (read-only) | Returns the declared layer name, "" for an anonymous layer, or null if no layer was declared. |
supportsText | CSSOMString? (read-only) | Returns the serialized <supports-condition> text (e.g. "(display: flex) or (display: block)"), or null if no supports() clause is present. |
cssText | CSSOMString (inherited from CSSRule) | Returns the serialized @import rule string. |
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:
TypeErroron unchecked dereference: Script that walkssheet.cssRulesand writesrule.styleSheet.cssRuleswithout checkingrule.styleSheet !== nullwill now throwTypeError: Cannot read properties of null (reading 'cssRules')in Chrome 159+ when encountering an@importwith a falsesupports()condition (matching Firefox and WebKit). Guard with optional chaining (rule.styleSheet?.cssRules) or an explicitif (rule.styleSheet)check.SecurityErroron cross-origin sheets: Whenrule.styleSheetis non-null, readingrule.styleSheet.cssRuleson a cross-origin stylesheet served without CORS headers still throwsDOMException(SecurityError) per standard CSSOM origin checks; wrap recursive stylesheet walkers intry { ... } catch.- Read-only assignment: Assigning to read-only attributes (
styleSheet,href,layerName, orsupportsText) fails silently in sloppy mode and throws aTypeErrorin strict mode; by contrast, assigning a string tomediasucceeds via[PutForwards=mediaText]. - Android WebView note: ChromeStatus notes the same null-check compatibility risk applies to embedded Android WebView content; the change is guarded by
CSSImportRuleStyleSheetNullable.
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).
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
| Browser | Nullable styleSheet | Evidence / notes | Base CSSImportRule.styleSheet (BCD) |
|---|---|---|---|
| Chrome (desktop, Android, WebView) | 159 | Enabled by default via CSSImportRuleStyleSheetNullable (CL 5065830) per ChromeStatus API record; Chrome on iOS listed as null (unconfirmed) | 1 |
| Edge | Unknown (Chromium 159) | Chromium-based; inherits Chromium 159 behavior (no separate BCD subfeature) | 12 |
| Firefox | Shipped | Already supports nullable CSSImportRule.styleSheet per Bugzilla 1427715#c12 and ChromeStatus (exact subfeature version not recorded in BCD) | 1 |
| Safari | Shipped (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 BCD | 1 |
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).
Specifications
see also
- MDN —
CSSImportRule.styleSheet(base reference; not yet updated for nullable return on falsesupports()as of 2026-11-24) - MDN —
CSSImportRule - Mozilla Bugzilla 1427715#c12
- WebKit PR #42784 — nullable
CSSImportRule.styleSheetIDL - Chromium CL 5065830
- ChromeStatus — CSSImportRule.styleSheet (5123480866783232)