horizontal-viewport-segments CSS media feature

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The horizontal-viewport-segments CSS media feature detects whether the device has a specified number of viewport segments laid out horizontally (side by side).

Related to the Viewport Segments API, the vertical-viewport-segments feature can be used to create responsive designs that work well on multi-viewport devices — devices with a display that is divided into logically separate viewport segments, such as foldable or hinged devices.

Syntax

The horizontal-viewport-segments feature is specified as an <integer> value of 1 or greater, representing the number of horizontal viewport segments the device has.

  • The value will be 1 for:
    • A non-foldable device (for example, a standard single-screen smartphone or tablet)
    • A foldable device that is either unfolded or closed (in the continuous device posture).
    • A two-screen hinged device or a foldable device that is currently folded and is oriented vertically so the segments are on top of each other.
  • The value will be 2 for a two-screen hinged device or a foldable device that is currently folded (in the folded device posture) and is oriented horizontally so the segments are side by side.
  • The value may be greater than 2 for foldable devices with more than one fold.

Examples

Basic horizontal-viewport-segments usage

In this snippet we use a horizontal-viewport-segments media query to handle the case of foldable devices where the segments are side-by-side.

We set the left container to have a width equal to the left segment width (env(viewport-segment-width 0 0)), and the right container to have a width equal to the right segment width (env(viewport-segment-width 1 0)).

To calculate how much width the fold takes up in between the two, we subtract the left edge offset of the right container from the right edge offset of the left container (calc(env(viewport-segment-left 1 0) - env(viewport-segment-right 0 0));).

css
.wrapper {
  height: 100%;
  display: flex;
}

@media (horizontal-viewport-segments: 2) {
  .wrapper {
    flex-direction: row;
  }

  .list-view {
    width: env(viewport-segment-width 0 0);
  }

  .fold {
    width: calc(
      env(viewport-segment-left 1 0) - env(viewport-segment-right 0 0)
    );
    background-color: black;
    height: 100%;
  }

  .detail-view {
    width: env(viewport-segment-width 1 0);
  }
}

See our Viewport segment API demo for a full working demo (source code). Also check out Using the Viewport Segments API for a full demo explanation.

Specifications

Specification
Media Queries Level 5
# mf-horizontal-viewport-segments

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
horizontal-viewport-segments
Experimental
Chrome – Full support
Chrome 138 (Release date: 2025-06-24)
footnote Full support
Edge – Full support
Edge 138 (Release date: 2025-06-26)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 122 (Release date: 2025-09-11)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 138 (Release date: 2025-06-24)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Full support
Opera Android 91 (Release date: 2025-08-19)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – Full support
WebView Android 138 (Release date: 2025-06-24)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.

See also