Safari 27.1 previews web APIs for foldable screens

· 6 min read

#apple-dev

Safari 27.1 ships with iPhone Duo, and it adds two web APIs for folding screens: Device Posture and Viewport Segments. Both are developer previews behind feature flags, so this post is about trying them, not shipping against them.

What WebKit says is new

WebKit's October 23 post says Safari 27.1 uses the same WebKit engine and web technologies as before, so existing sites and web apps should work unchanged on iPhone Duo. The new part is two APIs that tell your page about the fold. WebKit says the APIs may still change and asks for feedback, which is the usual language for a preview.

Device Posture: is the screen folded?

Device Posture has two values. folded means the device is partly folded, like a book or a laptop. continuous means the screen is flat, which includes fully open and fully closed. MDN adds that a device that cannot fold is always continuous, which makes a handy default: your normal layout is the continuous one.

You can read it in CSS or in JavaScript:

@media (device-posture: folded) {
  /* the screen is partly folded */
}
const posture = navigator.devicePosture.type; // "folded" or "continuous"

The JavaScript side also fires a change event when the posture changes.

Viewport Segments: where does the screen split?

When the device is partly folded, the viewport has segments. Viewport Segments gives you their position and size. There are media queries, horizontal-viewport-segments for side by side (the book pose) and vertical-viewport-segments for stacked (the laptop pose), and six CSS environment variables: viewport-segment-width, -height, -top, -right, -bottom and -left. Each takes two indexes, column first and then row, where the top left segment is 0 0. Side by side, the left segment is 0 0 and the right one is 1 0. Stacked, the top is 0 0 and the bottom is 0 1.

In JavaScript, window.viewport.segments returns an array of DOMRect objects. WebKit says to read it again when the posture changes and when the window size changes, so do not cache it at load.

Here is a small sketch of my own, not WebKit's sample, to show the shape of the idea:

@media (horizontal-viewport-segments: 2) {
  .sidebar {
    width: env(viewport-segment-width 0 0);
  }
}

It asks for the width of the left segment and gives it to a sidebar, only when the page is split side by side.

How wide is the viewport, really?

WebKit lists the viewport sizes in CSS pixels. Across the outer and inner screens, in portrait and landscape, widths run from 382 to 951 and heights from 368 to 902. Here are the widths:

iPhone Duo viewport width in Safari 27.1 Five boxes show the viewport width in CSS pixels: 382 on the outer screen in portrait, 594 on the outer screen in landscape, 669 on the inner screen in portrait, 951 on the inner screen in landscape, and 385 for each window when two windows sit side by side. A bar under each number shows the width to scale. Outer screen portrait 382 Outer screen landscape 594 Inner screen portrait 669 Inner screen landscape 951 Two windows inner, each 385
Viewport width in CSS pixels on iPhone Duo, from WebKit's Safari 27.1 post. The bars are to scale.

WebKit itself says not to memorize these numbers. Its advice is the old one: media queries, flexible layouts, CSS Grid and Flexbox, and feature detection instead of user-agent sniffing. The diagram is there to show how much the width moves, not to give you breakpoints.

What is still rough

Two things from the post stand out.

First, WebKit describes the outer screen as wider and shorter, and iOS pulls its controls to the edge. Safari 27.1 does not extend web content behind those edge controls. It fills that area with the page's background color. viewport-fit="cover" is one way around it, but WebKit says many sites do not inset all four edges correctly, and the team is looking for a sturdier approach. There is no promise or date.

Second, a plain user-facing change: partly folded, Safari shows PDFs as two pages side by side, and goes back to one page when the screen is flat or closed. Nothing for you to do there.

What I could not find out

WebKit's post does not mention WKWebView or SFSafariViewController. Whether the two flags work in web views inside apps is not stated anywhere I could check, so treat it as unknown. If your app shows web content, test that case yourself before you assume anything.

How to try it

  1. Use Xcode 27.1 or later. WebKit's post and Apple's iPhone Duo Prepare page both point to the iPhone Duo simulator, and Apple lists the iOS resizable simulator in Device Hub next to it.
  2. In the Settings app, go to Apps, then Safari, then Advanced, then Feature Flags. Turn on both "Device Posture API" and "Viewport Segments API". They are separate switches. I could not confirm from the sources that the simulator shows the same list, so look for it there.
  3. Open a page of yours in Safari, add one of the queries above and see whether it matches.

My suggestions, not facts

MDN marks both APIs as experimental with limited availability and not Baseline. That is the fact that matters most. My reading is that today the safe order is: make the page work at any width first, with the tools WebKit names, and treat posture as a small extra. A device-posture: folded rule that adds a second column is a good first use, because the page still works if the rule never matches. I would not make anything depend on the segment values until the APIs leave preview.

Sources