--- title: '@media' slug: Web/CSS/@media tags: - At-rule - CSS - Layout - NeedsTranslation - Reference - TopicStub - Web translation_of: Web/CSS/@media ---
{{ CSSRef() }}
The @media
CSS at-rule associates a set of nested statements, in a CSS block that is delimited by curly braces, with a condition defined by a media query. The @media
at-rule may be used not only at the top level of a CSS, but also inside any CSS conditional-group at-rule.
The @media
at-rule can be accessed via the CSS object model interface {{domxref("CSSMediaRule")}}.
A <media-query>
is composed of a media type and/or a number of media features.
print
and screen
media types. The FullerScreen extension enables support for the projection
media type.tty
, tv
, projection
, handheld
, braille
, embossed
, aural
), but they were deprecated in Media Queries 4 and shouldn't be used.Definition. This section needs to be expanded to explain media conditions in more depth.
Name | Summary | Notes |
---|---|---|
width |
Viewport width | |
height |
Viewport height | |
aspect-ratio |
Width-to-height aspect ratio of the viewport | |
orientation |
Orientation of the viewport | |
resolution |
Pixel density of the output device | |
scan |
Scanning process of the output device | |
grid |
Is the device a grid or bitmap? | |
update-frequency |
How quickly (if at all) can the output device modify the appearance of the content | Added in Media Queries Level 4 |
overflow-block |
How does the output device handle content that overflows the viewport along the block axis? | Added in Media Queries Level 4 |
overflow-inline |
Can content that overflows the viewport along the inline axis be scrolled? | Added in Media Queries Level 4 |
color |
Number of bits per color component of the output device, or zero if the device isn't color. | |
color-index |
Number of entries in the output device's color lookup table, or zero if the device does not use such a table. | |
monochrome |
Bits per pixel in the output device's monochrome frame buffer, or 0 if the device is not monochrome. | |
inverted-colors |
Is the user agent or underlying OS inverting colors? | Added in Media Queries Level 4 |
pointer |
Is the primary input mechanism a pointing device, and if so, how accurate is it? | Added in Media Queries Level 4 |
hover |
Does the primary input mechanism allow the user to hover over elements? | Added in Media Queries Level 4 |
any-pointer |
Is any available input mechanism a pointing device, and if so, how accurate is it? | |
any-hover |
Does any available input mechanism allow the user to hover over elements? | |
light-level |
Current ambient light level | Added in Media Queries Level 4 |
scripting |
Is scripting (e.g. JavaScript) available? | Added in Media Queries Level 4 |
device-width {{obsolete_inline}} |
Width of the rendering surface of the output device | Deprecated in Media Queries Level 4 |
device-height {{obsolete_inline}} |
Height of the rendering surface of the output device | Deprecated in Media Queries Level 4 |
device-aspect-ratio {{obsolete_inline}} |
Width-to-height aspect ratio of the output device | Deprecated in Media Queries Level 4 |
-webkit-device-pixel-ratio {{non-standard_inline}} |
Number of physical device pixels per CSS pixel | Nonstandard; WebKit/Blink-specific. If possible, use the resolution media feature instead. |
-webkit-transform-3d {{non-standard_inline}} |
Are CSS 3D {{cssxref("transform")}}s supported? | Nonstandard; WebKit/Blink-specific |
-webkit-transform-2d {{non-standard_inline}} |
Are CSS 2D {{cssxref("transform")}}s supported? | Nonstandard; WebKit-specific |
-webkit-transition {{non-standard_inline}} |
Are CSS {{cssxref("transition")}}s supported? | Nonstandard; WebKit-specific |
-webkit-animation {{non-standard_inline}} |
Are CSS {{cssxref("animation")}}s supported? | Nonstandard; WebKit-specific |
@media print { body { font-size: 10pt } } @media screen { body { font-size: 13px } } @media screen, print { body { line-height: 1.2 } }
Specification | Status | Comment |
---|---|---|
{{SpecName('CSS3 Conditional', '#at-media', '@media')}} | {{Spec2('CSS3 Conditional')}} | Defines the basic syntax of the @media rule. |
{{SpecName('CSS4 Media Queries', '#media', '@media')}} | {{Spec2('CSS4 Media Queries')}} |
Added |
{{SpecName('CSS3 Media Queries', '#media0', '@media')}} | {{Spec2('CSS3 Media Queries')}} | No change. |
{{SpecName('CSS2.1', 'media.html#at-media-rule', '@media')}} | {{Spec2('CSS2.1')}} | Initial definition. |