Skip to content

Conversation

chrisdavidmills
Copy link
Contributor

Description

Chrome 138 adds the Viewport Segments API, which provides a way to access the position and dimensions of logically separate viewport regions. 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).

The API is made up of several related features:

See also the related ChromeStatus entry: https://chromestatus.com/feature/5170498990243840

This PR adds docs for these new features. Specifically, it:

  • Adds a Viewport segments API landing page and "Using..." guide
  • Adds an API reference for Viewport and Window.viewport.
  • Adds the new media features to the media queries module page and @media landing page.
  • Adds information about the new environment variables to the env() page, and generally cleans up the structure of the page a bit.

Motivation

Additional details

Related issues and pull requests

@chrisdavidmills chrisdavidmills requested review from a team as code owners July 25, 2025 11:36
@chrisdavidmills chrisdavidmills requested review from estelle, sideshowbarker and pepelsbey and removed request for a team July 25, 2025 11:36
@github-actions github-actions bot added Content:CSS Cascading Style Sheets docs Content:WebAPI Web API docs labels Jul 25, 2025
@chrisdavidmills chrisdavidmills changed the title Add docs for the viewport segments api Technical review: Add docs for the viewport segments api Jul 25, 2025
@github-actions github-actions bot added the size/l [PR only] 501-1000 LoC changed label Jul 25, 2025
Copy link
Contributor

github-actions bot commented Jul 25, 2025

Preview URLs (13 pages)
Flaws (11)

Note! 7 documents with no flaws that don't need to be listed. 🎉

URL: /en-US/docs/Web/API/Viewport_segments_API
Title: Viewport Segments API
Flaw count: 2

  • broken_links:
    • Can't resolve /en-US/docs/Web/API/Viewport_API
  • unknown:
    • Invalid slug for templ/sidebar: Viewport segments API

URL: /en-US/docs/Web/API/Viewport_segments_API/Using
Title: Using the Viewport Segments API
Flaw count: 1

  • unknown:
    • Invalid slug for templ/sidebar: Viewport segments API

URL: /en-US/docs/Web/API/Window
Title: Window
Flaw count: 2

  • macros:
    • Macro produces link /en-US/docs/Web/API/HTMLElement/invalid_event which is a redirect
    • Macro produces link /en-US/docs/Web/API/Element/select_event which is a redirect

URL: /en-US/docs/Web/API/Window/viewport
Title: Window: viewport property
Flaw count: 1

  • broken_links:
    • Can't resolve /en-US/docs/Web/API/Viewport_API

URL: /en-US/docs/Web/CSS/@media
Title: @media
Flaw count: 2

  • broken_links:
    • Can't resolve /en-US/docs/Web/CSS/media-query-list
    • Can't resolve /en-US/docs/Web/CSS/rule-list

URL: /en-US/docs/Web/CSS/env
Title: env()
Flaw count: 3

  • broken_links:
    • Can't resolve /en-US/docs/Web/CSS/declaration-value
  • unknown:
    • Error serializing baseline for numeric-seperators: missing field description``
    • Error serializing baseline for single-color-gradients: missing field description``
External URLs (12)

URL: /en-US/docs/Web/API/Viewport
Title: Viewport


URL: /en-US/docs/Web/API/Viewport_segments_API
Title: Viewport Segments API


URL: /en-US/docs/Web/API/Viewport_segments_API/Using
Title: Using the Viewport Segments API


URL: /en-US/docs/Web/API/Viewport/segments
Title: Viewport: segments property


URL: /en-US/docs/Web/CSS/@media/horizontal-viewport-segments
Title: horizontal-viewport-segments


URL: /en-US/docs/Web/CSS/@media/vertical-viewport-segments
Title: vertical-viewport-segments


URL: /en-US/docs/Web/CSS/env
Title: env()

(comment last updated: 2025-09-18 09:53:27)

@chrisdavidmills
Copy link
Contributor Author

Hi @darktears! This PR contains the viewport segments API docs to accompany the demo you reviewed earlier in the week.

Would you be OK to provide a technical review of these, too? It isn't super-urgent; I'm on vacation next week anyway, so you've got plenty of time.

@sideshowbarker sideshowbarker removed their request for review July 26, 2025 00:43
@estelle estelle removed their request for review July 31, 2025 12:15
@github-actions github-actions bot added the merge conflicts 🚧 [PR only] label Aug 4, 2025

This comment was marked as resolved.

@github-actions github-actions bot removed the merge conflicts 🚧 [PR only] label Aug 4, 2025
@chrisdavidmills
Copy link
Contributor Author

Thanks a lot for the review, @darktears; let me know if you have any other comments or concerns.

Copy link
Member

@estelle estelle left a comment

Choose a reason for hiding this comment

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

rereview of env().

please don't hate me.

Copy link
Member

@estelle estelle left a comment

Choose a reason for hiding this comment

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

env() page again.

@estelle estelle mentioned this pull request Sep 9, 2025
Copy link
Member

@estelle estelle left a comment

Choose a reason for hiding this comment

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

didn't finish.

did create a module landing page for viewport mod - #41070 assume that should go live when this does

Copy link
Member

@estelle estelle left a comment

Choose a reason for hiding this comment

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

A few comments to go with the PR chrisdavidmills#13


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

The {{cssxref("@media/horizontal-viewport-segments")}} media feature detects whether the device has a specified number of viewport segments laid out horizontally, whereas the {{cssxref("@media/vertical-viewport-segments")}} media feature detects whether the device has a specified number of viewport segments laid out vertically.

> [!NOTE]
> Current implementations do not support more than two foldable screens.
Copy link
Member

Choose a reason for hiding this comment

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

Where does this information come from? bug / ticket #?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@darktears, the engineer who implemented this stuff, told me this.

}
```

Here, we are setting the outer wrapper to have a horizontal flexbox layout when the viewport segments are laid out horizontally. We then set the left container to have a width equal to the left segment width, and the right container to have a width equal to the right segment width. 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.
Copy link
Member

Choose a reason for hiding this comment

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

this is identical to below. I wrote a grid example to replace this section

## Example walkthrough

Let's look at these features in action in a real example. You can see our example running live at [Viewport segment API demo](https://mdn.github.io/dom-examples/viewport-segment-api/) (see the full [source code](https://github.com/mdn/dom-examples/tree/main/viewport-segment-api) also). 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.

Copy link
Member

Choose a reason for hiding this comment

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

Adding an attribution


The `viewport` read-only property of the {{domxref("Window")}} interface returns a {{domxref("Viewport")}} object instance, which provides information about the current state of the device's viewport.

This property can be considered the entry point to the [Viewport segments API](/en-US/docs/Web/API/Viewport_segments_API), which relies on viewport segment information returned by the {{domxref("Viewport.segments")}} property.
Copy link
Member

Choose a reason for hiding this comment

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

switched this to be more like other web-api-instance-property that are just placeholders for the same slug but without the /window/


### Basic `viewport` 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.
Copy link
Member

Choose a reason for hiding this comment

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

see comment above

Copy link
Member

@estelle estelle left a comment

Choose a reason for hiding this comment

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

Yay! Just one note to remove (or add a link to bug so we can track for removal at a later time)

@chrisdavidmills chrisdavidmills merged commit 7860297 into mdn:main Sep 18, 2025
9 checks passed
@chrisdavidmills chrisdavidmills deleted the viewport-segments-api branch September 18, 2025 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:CSS Cascading Style Sheets docs Content:WebAPI Web API docs size/l [PR only] 501-1000 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants