For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt, and this page is available as Markdown at /next/api/css/media-query.md.
Lynx
  • English
  • Media Query

    Lynx implements a subset of CSS Media Queries Level 4. Use @media rules to apply styles according to the viewport and other runtime environment values.

    Enable CSS Rule Encoding

    Media query rules require CSS Rule encoding. Add pluginLynxConfig to the existing plugins array in lynx.config.mjs:

    import { pluginLynxConfig } from '@lynx-js/config-rsbuild-plugin';
    
    export default defineConfig({
      plugins: [
        pluginLynxConfig({
          enableCSSRule: true,
        }),
      ],
    });

    enableCSSRule requires Lynx SDK or Clay 4.0 or later. Without it, @media rules are not encoded into the template and do not take effect at runtime.

    Syntax Support

    Media Types

    TypeLynx behaviorWeb behavior
    allAlways matchesAlways matches
    screenAlways matches; Lynx is a screen-only surfaceMatches only on screen devices
    printNever matchesMatches only in a print context
    Others (speech, tty, etc.)Never matchMatch their respective contexts

    Logical Modifiers and Operators

    Lynx supports not, only, comma-separated query lists (OR semantics), and and, or, and not media conditions. As in the CSS grammar, do not mix and and or at the same level without nesting a condition in parentheses.

    /* and / or / not combinations */
    @media (min-width: 600px) and (orientation: portrait) { ... }
    @media (hover) or (pointer) { ... }
    @media not (prefers-color-scheme: dark) { ... }
    
    /* Level 4 range syntax */
    @media (300px <= width <= 600px) { ... }
    @media (width > 400px) { ... }
    @media (100px < width < 500px) { ... }

    Range syntax uses the unprefixed feature name, such as width rather than min-width.

    Supported Media Features

    Viewport Dimensions

    FeatureSupported formsDescription
    widthplain / min- / max- / rangeViewport width in CSS pixels
    heightplain / min- / max- / rangeViewport height in CSS pixels
    device-widthplain / min- / max- / rangeEquivalent to width
    device-heightplain / min- / max- / rangeEquivalent to height

    The boolean form (width) matches when the viewport width is greater than zero.

    Aspect Ratio

    FeatureSupported formsDescription
    aspect-ratioplain / min- / max- / rangeViewport width divided by height
    device-aspect-ratioplain / min- / max- / rangeEquivalent to aspect-ratio

    Values can be ratios such as 16/9, or plain numbers interpreted as N/1.

    Resolution and Pixel Density

    FeatureSupported formsDescription
    resolutionplain / min- / max- / rangeDevice pixel ratio
    device-pixel-ratioplain / min- / max- / rangeUnitless device pixel ratio

    resolution accepts dppx, x, dpi, and dpcm. x is an alias for dppx.

    Orientation

    FeatureValuesDescription
    orientationportrait / landscapeportrait when height >= width

    A square viewport is considered portrait.

    Interaction Capabilities

    Note

    The host does not provide hover or pointer environment values. Related queries without a not modifier do not match.

    FeatureValuesDescription
    hoverhover / noneWhether the primary input supports hover
    pointerfine / coarse / noneWhether a primary pointer is present; fine and coarse are not distinguished

    User Preferences

    The host can update the system color scheme through UpdateColorScheme. The default value is light.

    FeatureValuesDescription
    prefers-color-schemelight / darkSystem color scheme preference

    Color Depth

    Note

    The host does not provide actual color-depth data. The runtime evaluates color depth as 8 bits per color component.

    FeatureSupported formsDescription
    colorplain / min- / max- / rangeBits per color component

    Supported Value Units

    Length Units

    UnitDescription
    pxCSS pixels
    emRelative to the current font size
    remRelative to the root element font size
    %Percentage of viewport width in media queries
    vwViewport width percentage
    vhViewport height percentage
    vminThe smaller of vw and vh
    vmaxThe larger of vw and vh

    Resolution Units

    UnitDescription
    dppxDots per CSS pixel
    xAlias for dppx
    dpiDots per inch; divide by 96 for dppx
    dpcmDots per centimeter; divide by 37.795 for dppx

    Key Differences from Web

    device-* Dimensions Use the Viewport

    Unlike the Web, Lynx does not expose a physical-device size through media queries. device-width, device-height, and device-aspect-ratio use the same viewport values as width, height, and aspect-ratio.

    Unsupported Features Fail Closed

    Media features not listed on this page are unrecognized and evaluate to false.

    The Media Type Is Always screen

    Lynx has a screen rendering context only:

    • @media print { ... } never applies.
    • @media not print { ... } always applies.
    • @media screen { ... } is equivalent to @media all { ... }.

    Invalid Query Lists Use not all

    When an entire media query list is invalid, Lynx replaces it with not all, so it never matches. In a comma-separated list, invalid entries are discarded while valid entries continue to participate in OR matching.

    Usage Examples

    /* Responsive layout */
    @media (min-width: 768px) {
      .container {
        flex-direction: row;
      }
    }
    
    /* Dark mode */
    @media (prefers-color-scheme: dark) {
      .card {
        background-color: #1a1a1a;
      }
    }
    
    /* High-DPR devices */
    @media (min-resolution: 2dppx) {
      .logo {
        background-image: url('logo@2x.png');
      }
    }
    
    /* Level 4 range syntax */
    @media (400px <= width <= 800px) {
      .sidebar {
        display: none;
      }
    }

    Compatibility

    LCD tables only load in the browser

    Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.