mozilla
Your Search Results

    media Redirect 3

    Summary

    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 CSSMediaRule.

    Syntax

    @media <media-query> {
      /* media-specific rules */
    }
    

    A <media-query> is composed of a media type and/or a number of media features.

    Media types

    Note: Firefox currently only implements the print and screen media types.  The FullerScreen extension enables support for the projection media type.
    all
    Suitable for all devices.
    print
    Intended for paged material and for documents viewed on screen in print preview mode. Please consult the section on paged media, and the media section of the Getting Started tutorial for information about formatting issues that are specific to paged media.
    screen
    Intended primarily for color computer screens.
    speech
    Intended for speech synthesizers. Note: CSS2 had a similar media type called 'aural' for this purpose. See the appendix on aural style sheets for details.
    Note: CSS2.1 and Media Queries 3 defined several additional media types, but they were deprecated in Media Queries 4 and shouldn't be used.

    Media Features

    Definition, and start of media features list. This section needs to be expanded to explain media conditions in more depth.

    Name Type, or possible enumerated values Summary Notes
    width <length> Viewport width  
    height <length> Viewport height  
    aspect-ratio <ratio> Width-to-height aspect ratio of the viewport  
    orientation portrait | landscape Orientation of the viewport  
    resolution <resolution> Pixel density of the output device  
    scan interlace | progressive Scanning process of the output device  
    grid <mq-boolean> Is the device a grid or bitmap?  
    update-frequency none | slow | normal How quickly (if at all) can the output device modify the appearance of the content Added in Media Queries Level 4
    overflow-block none | scroll | optional-paged | paged How does the output device handle that overflows the viewport along the block axis? Added in Media Queries Level 4
    overflow-inline none | scroll Can content that overflows the viewport along the inline axis be scrolled? Added in Media Queries Level 4
    color <integer> Number of bits per color component of the output device, or zero if the device isn't color.  
    color-index <integer> Number of entries in the output device's color lookup table, or zero if the device does not use such a table.  
    monochrome <integer> Bits per pixel in the output device's monochrome frame buffer, or 0 if the device is not monochrome.  
    inverted-colors none | inverted Is the user agent or underlying OS inverting colors?  
    pointer none | coarse | fine Is the primary input mechanism a pointing device, and if so, how accurate is it? Added in Media Queries Level 4
    hover none | on-demand | hover Does the primary input mechanism allow the user to hover over elements? Added in Media Queries Level 4
    any-pointer none | coarse | fine Is any available input mechanism a pointing device, and if so, how accurate is it? Chromium bug 398943: Ship 'any-pointer' and 'any-hover' Media Queries
    any-hover none | on-demand | hover Does any available input mechanism allow the user to hover over elements? Chromium bug 398943: Ship 'any-pointer' and 'any-hover' Media Queries
    light-level dim | normal | washed Current ambient light level Added in Media Queries Level 4
    scripting none | initial-only | enabled Is scripting (e.g. JavaScript) available? Added in Media Queries Level 4
    device-width <length> Width of the rendering surface of the output device Deprecated in Media Queries Level 4
    device-height <length> Height of the rendering surface of the output device Deprecated in Media Queries Level 4
    device-aspect-ratio <ratio> Width-to-height aspect ratio of the output device Deprecated in Media Queries Level 4

    Examples

    @media print {
      body { font-size: 10pt }
    }
    @media screen {
      body { font-size: 13px }
    }
    @media screen, print {
      body { line-height: 1.2 }
    }
    

    Specifications

    Specification Status Comment
    Media Queries Level 4
    The definition of '@media' in that specification.
    Working Draft

    Added scripting, pointer, hover, light-level, update-frequency, overflow-block, and overflow-inline media features.
    Deprecated all media types except for screen, print, speech, and all.

    Media Queries
    The definition of '@media' in that specification.
    Recommendation No change.
    CSS Level 2 (Revision 1)
    The definition of '@media' in that specification.
    Recommendation Initial definition.

    Browser compatibility

    Help improve compatibility tables by filling out this 11 question survey.

    Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
    Basic support 1.0 1.0 (1.7 or earlier) 9.0 9.2 1.3
    Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
    Basic support 1.0 1.0 (1.7) 9.0 9.0 3.1

    See also

    Document Tags and Contributors

    Contributors to this page: Sheppy
    Last updated by: Sheppy,
    Hide Sidebar