Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
ea6ac48
Add docs for the viewport segments api
chrisdavidmills Jul 25, 2025
b559269
Merge branch 'main' into viewport-segments-api
chrisdavidmills Jul 25, 2025
1e56e76
rename wrongly-named directory
chrisdavidmills Jul 25, 2025
bbf33cf
Merge branch 'viewport-segments-api' of github.com:chrisdavidmills/co…
chrisdavidmills Jul 25, 2025
f93fa22
Merge branch 'main' into viewport-segments-api
chrisdavidmills Aug 4, 2025
8d158ae
Merge branch 'main' into viewport-segments-api
chrisdavidmills Aug 5, 2025
07afeac
Fixes for darktears review comments
chrisdavidmills Aug 5, 2025
7ca1134
A couple of further language tweaks
chrisdavidmills Aug 7, 2025
d6106dd
Merge branch 'main' into viewport-segments-api
chrisdavidmills Aug 20, 2025
3e61ee4
Update files/en-us/web/api/viewport/index.md
chrisdavidmills Aug 28, 2025
5aa42f6
Update files/en-us/web/css/env/index.md
chrisdavidmills Aug 28, 2025
931792f
Update files/en-us/web/css/@media/vertical-viewport-segments/index.md
chrisdavidmills Aug 28, 2025
8f15a09
Update files/en-us/web/css/@media/vertical-viewport-segments/index.md
chrisdavidmills Aug 28, 2025
a6002f7
Update files/en-us/web/css/@media/index.md
chrisdavidmills Aug 28, 2025
61a1ccc
Update files/en-us/web/css/env/index.md
chrisdavidmills Aug 28, 2025
c46c455
Update files/en-us/web/css/env/index.md
chrisdavidmills Aug 28, 2025
53410e0
Fixes for estelle review comments
chrisdavidmills Aug 28, 2025
57710d1
Update files/en-us/web/css/env/index.md
chrisdavidmills Sep 1, 2025
d68c717
Fixes for estelle review comments
chrisdavidmills Sep 1, 2025
fb04f87
Fixes for estelle review comments
chrisdavidmills Sep 4, 2025
bc9a072
Update files/en-us/web/css/env/index.md
chrisdavidmills Sep 9, 2025
0b65c26
Update files/en-us/web/css/env/index.md
chrisdavidmills Sep 9, 2025
1a1371d
Update files/en-us/web/css/css_environment_variables/index.md
chrisdavidmills Sep 9, 2025
32ba8bb
Update files/en-us/web/css/css_environment_variables/index.md
chrisdavidmills Sep 9, 2025
3a2461d
Merge branch 'main' into viewport-segments-api
chrisdavidmills Sep 9, 2025
348ffa9
Fixes for estelle review comments
chrisdavidmills Sep 9, 2025
32ac90e
Small wording upddate
chrisdavidmills Sep 9, 2025
81ed4fb
Merge branch 'main' into viewport-segments-api
estelle Sep 15, 2025
aa7a694
remote edits to PR
estelle Sep 16, 2025
d7f14d3
groupdata capitalization
estelle Sep 16, 2025
b348abd
Merge pull request #13 from mdn/segments
chrisdavidmills Sep 17, 2025
4a83e58
Remove incorrect inheritance claim
chrisdavidmills Sep 17, 2025
36b3b8a
Edit grammar
chrisdavidmills Sep 17, 2025
2134dbe
grammar fixes, fill in missing URLs
chrisdavidmills Sep 17, 2025
dd943db
Update files/en-us/web/api/viewport_segments_api/using/index.md
chrisdavidmills Sep 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions files/en-us/web/api/viewport/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
title: Viewport
slug: Web/API/Viewport
page-type: web-api-interface
status:
- experimental
browser-compat: api.Viewport
---

{{APIRef("Viewport segments API")}}{{SeeCompatTable}}

The **`Viewport`** interface of the {{domxref("Viewport segments API", "Viewport segments API", "", "nocode")}} represents the device's viewport.

{{InheritanceDiagram}}

## Instance properties

_Inherits properties from its parent, {{DOMxRef("EventTarget")}}._
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this accurate?
I am not seeing anything about {{DOMxRef("EventTarget")}} being the parent. I thought Window was the parent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect this was a copy and paste error. I'll fix it.


- {{domxref("Viewport.segments", "segments")}} {{ReadOnlyInline}} {{Experimental_Inline}}
- : Returns an array of {{domxref("DOMRect")}} objects representing the position and dimensions of each viewport segment within the overall display.

## Examples

### Basic `Viewport.segments` usage

This snippet will loop through each segment in the viewport, and log a string to the console detailing the index number, width, and height.

```js
const segments = window.viewport.segments;

segments.forEach((segment) =>
console.log(
`Segment ${segments.indexOf(segment)} is ${segment.width}px x ${segment.height}px`,
),
);
```

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- [Viewport segments API](/en-US/docs/Web/API/Viewport_segments_API)
- [Origin trial for Foldable APIs](https://developer.chrome.com/blog/foldable-apis-ot) on developer.chrome.com (2024)
46 changes: 46 additions & 0 deletions files/en-us/web/api/viewport/segments/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
title: "Viewport: segments property"
short-title: segments
slug: Web/API/Viewport/segments
page-type: web-api-instance-property
status:
- experimental
browser-compat: api.Viewport.segments
---

{{APIRef("Viewport segments API")}}{{SeeCompatTable}}

The **`segments`** read-only property of the {{domxref("Viewport")}} interface returns an array of {{domxref("DOMRect")}} objects representing the position and dimensions of each viewport segment within the overall display.

## Value

An array of {{domxref("DOMRect")}} objects.

## Examples

### Basic `Viewport.segments` usage

This snippet will loop through each segment in the viewport, and log a string to the console detailing the index number, width, and height.

```js
const segments = window.viewport.segments;

segments.forEach((segment) =>
console.log(
`Segment ${segments.indexOf(segment)} is ${segment.width}px x ${segment.height}px`,
),
);
```

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- [Viewport segments API](/en-US/docs/Web/API/Viewport_segments_API)
- [Origin trial for Foldable APIs](https://developer.chrome.com/blog/foldable-apis-ot) on developer.chrome.com (2024)
60 changes: 60 additions & 0 deletions files/en-us/web/api/viewport_segments_api/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
title: Viewport segments API
slug: Web/API/Viewport_segments_API
page-type: web-api-overview
status:
- experimental
browser-compat: api.Viewport.segments
---

{{DefaultAPISidebar("Viewport segments API")}}{{seecompattable}}

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 is difficult to know whether a user's device screen has a fold or join, what size the different segments are and whether they are the same size, and what orientation they are in (side-by-side or top-to-bottom).

The Viewport Segments API was created to handle such challenges. It does this with a combination of CSS and JavaScript features that provide access to the position and dimensions each viewport segment within the overall display, plus `@media` features to detect different horizontal and vertical region layouts.

For an explanation of how the API works, see [Using the Viewport segments API](/en-US/docs/Web/API/Viewport_segments_API/Using).

## Interfaces

- {{domxref("Viewport")}}
- : Represents the device's viewport. Provides access to the {{domxref("Viewport.segments")}} property, which returns an array of {{domxref("DOMRect")}} objects representing the position and dimensions of each viewport segment within the overall display.

### Extensions to other interfaces

- {{domxref("Window.viewport")}}
- : Returns a `Viewport` object instance, which provides information about the current state of the device's viewport.

## CSS features

- {{cssxref("@media/horizontal-viewport-segments", "horizontal-viewport-segments")}} `@media` feature
- : Detects whether the device has a specified number of viewport segments laid out horizontally.
- {{cssxref("@media/vertical-viewport-segments", "vertical-viewport-segments")}} `@media` feature
- : Detects whether the device has a specified number of viewport segments laid out vertically.
- [Viewport segment environment variables](/en-US/docs/Web/CSS/env#viewport-segment-width)
- : These `env()` 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](https://mdn.github.io/dom-examples/viewport-segment-api/).

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

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- [Device Posture API](/en-US/docs/Web/API/Device_Posture_API)
- [Origin trial for Foldable APIs](https://developer.chrome.com/blog/foldable-apis-ot) on developer.chrome.com (2024)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading