Viewport Segments API

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 Viewport Segments API allows developers to access the position and dimensions of logically separate viewport segments using CSS and JavaScript. Viewport segments are created when the viewport is split by one or more hardware features such as a fold or a hinge between separate displays. With the Viewport Segments API, developers can create responsive designs optimized for different viewport segment sizes and arrangements.

Concepts and usage

Devices with multiple displays that are intended to act as different segments of the same display surface (think foldable or hinged screen smartphones) present some unique design challenges to developers. You can optimize your layout for the display as a single entity, but how can you ensure that design elements fit snugly on the different segments and are not cut into two pieces? And how can you prevent content from being hidden by the physical fold/join?

It may be important to know whether a user's device screen has a fold or join, what size the different segments are, whether they are the same size, and the orientation of the segments (whether they are side-by-side or top-to-bottom). The Viewport Segments API enables accessing the user's segmented device information with CSS and JavaScript features that provide access to the position and dimensions of each viewport segment within a display, including @media features to detect different horizontal and vertical region layouts.

For an explanation of how the API works, see Using the Viewport Segments API.

Interfaces

Viewport

Represents the device's viewport. Provides access to the Viewport.segments property, which returns an array of DOMRect objects representing the position and dimensions of each viewport segment within a segmented display.

Extensions to other interfaces

Window.viewport

Returns a Viewport object instance, which provides information about the current state of the device's viewport.

CSS features

horizontal-viewport-segments @media feature

Detects whether the device has a specified number of viewport segments laid out horizontally.

vertical-viewport-segments @media feature

Detects whether the device has a specified number of viewport segments laid out vertically.

Viewport segment environment variables

These environment variables provide access to the edge coordinates and dimensions of each viewport segment.

Examples

You can find a complete example demonstrating usage of the above features in the Viewport segment API demo.

If possible, you should view the demo on a foldable device. Current browser developer tools enable emulating foldable devices, but don't include emulation of the different physical segments.

Specifications

Specification
CSS Viewport Module Level 1
# dom-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
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