Firefox Tomorrow

web api instance property

CSSRule: type property

View on MDN ↗

The read-only type property of the CSSRule interface is a deprecated property that returns an integer indicating which type of rule the CSSRule represents.

If you need to distinguish different types of CSS rule, a good alternative is to use constructor.name:

const sheets = Array.from(document.styleSheets);
const rules = sheets.map((sheet) => Array.from(sheet.cssRules)).flat();

for (const rule of rules) {
  console.log(rule.constructor.name);
}

Value

The values CSSRule.UNKNOWN_RULE (0), CSSRule.CHARSET_RULE (2), CSSRule.DOCUMENT_RULE (13), CSSRule.VIEWPORT_RULE (14), and CSSRule.REGION_STYLE_RULE (16) cannot be obtained anymore.

Examples

const rules = document.styleSheets[0].cssRules;
console.log(rules[0].type);

Specifications

SpecificationsStandards references are available on the canonical MDN page.

Browser compatibility

Browser compatibilityCompatibility data is available on the canonical MDN page.