CSSRule.type
Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.
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
An integer which will be one of the type constants listed in the table below.
Type | Value | Rule-specific interface | Comments and examples |
---|---|---|---|
CSSRule.STYLE_RULE |
1 |
CSSStyleRule |
The most common kind of rule:selector { prop1: val1; prop2: val2; } |
CSSRule.IMPORT_RULE |
3 |
CSSImportRule |
An @import rule. (Until the documentation is
completed, see the interface definition in the Mozilla source code:
nsIDOMCSSImportRule.)
|
CSSRule.MEDIA_RULE |
4 |
CSSMediaRule |
|
CSSRule.FONT_FACE_RULE |
5 |
CSSFontFaceRule |
|
CSSRule.PAGE_RULE |
6 |
CSSPageRule |
|
CSSRule.KEYFRAMES_RULE |
7 |
CSSKeyframesRule
Experimental
|
|
CSSRule.KEYFRAME_RULE |
8 |
CSSKeyframeRule
Experimental
|
|
Reserved for future use | 9 |
Should be used to define color profiles in the future | |
CSSRule.NAMESPACE_RULE |
10 |
CSSNamespaceRule
Experimental
|
|
CSSRule.COUNTER_STYLE_RULE |
11 |
CSSCounterStyleRule
Experimental
|
|
CSSRule.SUPPORTS_RULE |
12 |
CSSSupportsRule |
|
CSSRule.DOCUMENT_RULE |
13 |
CSSDocumentRule
Experimental
|
|
CSSRule.FONT_FEATURE_VALUES_RULE |
14 |
CSSFontFeatureValuesRule |
|
CSSRule.VIEWPORT_RULE |
15 |
CSSViewportRule
Experimental
|
|
CSSRule.REGION_STYLE_RULE |
16 |
CSSRegionStyleRule
Experimental
|
|
CSSRule.UNKNOWN_RULE |
0 |
CSSUnknownRule
Deprecated
|
|
CSSRule.CHARSET_RULE |
2 |
CSSCharsetRule
Deprecated
|
(Removed in most browsers.) |
Examples
let myRules = document.styleSheets[0].cssRules;
console.log(myRules[0].type);
Specifications
Specification |
---|
CSS Object Model (CSSOM) # concept-css-rule-type |
Browser compatibility
BCD tables only load in the browser