The CSSMediaRule
interface represents a single CSS @media
rule.
<div id="interfaceDiagram" style="display: inline-block; position: relative; width: 100%; padding-bottom: 11.666666666666666%; vertical-align: middle; overflow: hidden;"><svg style="display: inline-block; position: absolute; top: 0; left: 0;" viewbox="-50 0 600 70" preserveAspectRatio="xMinYMin meet"><a xlink:href="https://developer.mozilla.org/en-US/docs/Web/API/CSSRule" target="_top"><rect x="1" y="1" width="75" height="50" fill="#fff" stroke="#D4DDE4" stroke-width="2px" /><text x="38.5" y="30" font-size="12px" font-family="Consolas,Monaco,Andale Mono,monospace" fill="#4D4E53" text-anchor="middle" alignment-baseline="middle">CSSRule</text></a><polyline points="76,25 86,20 86,30 76,25" stroke="#D4DDE4" fill="none"/><line x1="86" y1="25" x2="116" y2="25" stroke="#D4DDE4"/><a xlink:href="https://developer.mozilla.org/en-US/docs/Web/API/CSSGroupingRule" target="_top"><rect x="116" y="1" width="150" height="50" fill="#fff" stroke="#D4DDE4" stroke-width="2px" /><text x="191" y="30" font-size="12px" font-family="Consolas,Monaco,Andale Mono,monospace" fill="#4D4E53" text-anchor="middle" alignment-baseline="middle">CSSGroupingRule</text></a><polyline points="266,25 276,20 276,30 266,25" stroke="#D4DDE4" fill="none"/><line x1="276" y1="25" x2="306" y2="25" stroke="#D4DDE4"/><a xlink:href="https://developer.mozilla.org/en-US/docs/Web/API/CSSConditionRule" target="_top"><rect x="306" y="1" width="160" height="50" fill="#fff" stroke="#D4DDE4" stroke-width="2px" /><text x="386" y="30" font-size="12px" font-family="Consolas,Monaco,Andale Mono,monospace" fill="#4D4E53" text-anchor="middle" alignment-baseline="middle">CSSConditionRule</text></a><polyline points="466,25 476,20 476,30 466,25" stroke="#D4DDE4" fill="none"/><line x1="476" y1="25" x2="506" y2="25" stroke="#D4DDE4"/><a xlink:href="https://developer.mozilla.org/en-US/docs/Web/API/CSSMediaRule" target="_top"><rect x="506" y="1" width="120" height="50" fill="#F4F7F8" stroke="#D4DDE4" stroke-width="2px" /><text x="566" y="30" font-size="12px" font-family="Consolas,Monaco,Andale Mono,monospace" fill="#4D4E53" text-anchor="middle" alignment-baseline="middle">CSSMediaRule</text></a></svg></div>
a:hover text { fill: #0095DD; pointer-events: all;}
Properties
Inherits properties from its ancestors CSSConditionRule
, CSSGroupingRule
, and CSSRule
.
CSSMediaRule.media
Read only- Returns a
MediaList
representing the intended destination medium for style information.
Methods
No specific methods; inherits methods from its ancestors CSSConditionRule
, CSSGroupingRule
, and CSSRule
.
Examples
The CSS includes a media query with one style rule. This will be the first CSSRule returned by document.styleSheets[0].cssRules
.
myRules[0]
therefore returns a CSSMediaRule
object.
@media (min-width: 500px) {
body {
color: blue;
}
}
let myRules = document.styleSheets[0].cssRules;
console.log(myRules[0]); // a CSSMediaRule representing the media query.
Specifications
Specification | Status | Comment |
---|---|---|
CSS Conditional Rules Module Level 3 The definition of 'CSSMediaRule' in that specification. |
Candidate Recommendation | Make it derived from the CSSConditionRule . |
CSS Object Model (CSSOM) The definition of 'CSSMediaRule' in that specification. |
Working Draft | No changes from Document Object Model (DOM) Level 2 Style Specification |
Document Object Model (DOM) Level 2 Style Specification The definition of 'CSSMediaRule' in that specification. |
Obsolete |
Browser compatibility
BCD tables only load in the browser