Web APIs for Dual Screen and Foldable Devices – By Microsoft Edge


The browser is with out a doubt one of the important crucial mature apps on any instrument, and at the present time it’s running on a completely contemporary hardware class: twin-masks and foldable gadgets.

With a whole lot of most modern twin-masks and foldable gadgets coming to market, including remaining week’s launch of the contemporary Floor Duo, there’s by no map been the next time to commence fascinated with how your assign of abode can contain these blueprint factors.

This day, we’re happy to scream the offer of two contemporary experimental substances that can also support web developers successfully lay out speak in a browser window that spans a few hiss regions and win responsive web sites which are a pure match for this contemporary class of instrument:

The foldable instrument class

Broadly speaking, there are two variants of foldable gadgets: twin-masks gadgets, and single-masks gadgets that snatch succor of the versatile hiss expertise. Both luxuriate in loads on the total: they are portable, multi-posture gadgets that enable customers to rotate, flip and fold.

Illustration of dual-screen and single-screen foldable devices

On this blueprint component, applications can reside on one facet, or will seemingly be spanned across both hiss regions. A enviornment that responds to this spanned speak integrates with the semantics and intent of logically splitting the offered speak.

A dual-screen foldable device in various postures such as book mode, tent mode, and others.

The massive masks proper-estate and queer postures enabled by this instrument class enable web developers to liberate unprecedented experiences on the on-line in a instrument that can match on your pocket or purse.

Transitioning from primitive contiguous screens to twin-screens and foldables

Although existing web sites will proceed to determine-of-the-field, making web sites responsive to the foldable nature of the instrument can vastly pink meat up the user journey.

To better illustrate the replacement and account for how the newly created browser capabilities work, we’ll snatch you thru bettering an example email client layout.

Showing an inventory-note of the inbox and the speak of an email facet-by-facet is a total sample that is naturally tremendous for wider viewing areas. When the browser window is spanned across the two hiss regions on a twin-masks instrument, the total viewport width is prone to be the same to that of a primitive landscape capsule instrument.

Examples of an email client with and without optimizations for a dual-screen layout

Unmodified, the email client will proceed to work because it frequently has. Nonetheless, the journey will seemingly be dramatically improved if we would possibly possibly align the inbox and the email columns with the fold, conserving each and every inside of the boundaries of a single hiss station. That map, neither speak condo will seemingly be reduce or masked by the instrument hinge or rendered over the fold of a versatile hiss.

To provide the specified layout, we’re introducing a brand contemporary masks-spanning media feature and a hassle of pre-defined atmosphere variables that enable web developers to treat foldable gadgets as one more responsive web win target. Developers can now win layouts that adapt to every instrument class without taking a exhausting dependency on particular hardware parameters. This flexibility improves scalability because it would no longer require duplication of work for each and every contemporary instrument form.

Detecting hiss regions

The CSS masks-spanning media feature can also support web developers test if the root viewport is being spanned across a few adjoining hiss regions, and provide tiny print in regards to the configuration of these adjoining hiss regions (e.g. stacked or facet-by-facet).


The masks-spanning media feature is specified as a value describing the number of folds (or hinges) the instrument has, besides their postures. If the instrument is now no longer a foldable instrument, the value is none. If it is some distance a foldable, it would possibly possibly possibly probably presumably luxuriate in with out a doubt the kind of two values:

  • Single-fold-vertical: suits a instrument with a single fold (two hiss regions) and the fold posture is vertical.
  • Single-fold-horizontal: suits a instrument with a single fold (two hiss regions) and the fold posture is horizontal.

Comparison between single-fold-vertical and single-fold-horizontal values for screen-spanning.

Calculating hiss regions geometry

It’s now no longer gracious to raise that after in the masks-spanning speak, the fold is incessantly going to divide the viewport exactly in half. Additionally, some window managers would possibly possibly snatch to masks the on-line speak in the back of the fold. To support web developers calculate the size of each and every hiss station and win certain they know how worthy their speak, if any, has to be padded to steer certain of the masks, we’re adding four predefined CSS atmosphere variables.

  • env(fold-high)
  • env(fold-left)
  • env(fold-width)
  • env(fold-height)

illustration labelling environment variables on different display regions

The values of these variables are expressed in CSS pixels and are relative to the layout viewport (i.e. are in the patron coordinates, as defined by CSSOM Views). When evaluated in speak that’s now no longer in with out a doubt one of the important spanning states, these values will seemingly be handled as in the event that they don’t exist, and the browser will exhaust the fallback value as handed to the env() feature.

Enhancing our email example app for twin-masks and foldable experiences

A side by side example showing a mail app with content occluded by a hinge gap, and with a layout that accounts for the hinge gap

Let’s attach the CSS masks-spanning media feature and the fold geometry atmosphere variables into insist and pink meat up the reader note of our email client:

Enumerating the window segments in JavaScript

When working with non-DOM targets admire Canvas2d or WebGL, it is possible you’ll presumably presumably also win the geometry of each and every hiss station using the contemporary Window Segments Enumeration API.

getWindowSegments() is a mode on the Window object that returns an array of 1 or extra DOMRects representing the geometry and assign of abode of each and every hiss station.

The returned array is an immutable snapshot of the hiss regions’ speak at the time the device became once called. If the user transitions from a spanning speak to a non-spanning speak, or rotates the instrument, the window segments beforehand retrieved will seemingly be invalid.

Pages ought to be wide awake of window resize match or orientationchange match to detect whether the browser became once resized, or the instrument became once rotated and retrieve the up to this point hiss regions.

There don’t seem like any express ideas to be taught whether the fold posture is vertical or horizontal, as this data can without grief calculated from the DOMRects returned:

Same applies for the fold-width, web developers can exhaust data offered by getWindowSegments() to be taught whether the window manager is conserving speak rendered in the back of the fold, and the fold width is bigger than zero pixels, or now no longer.


As developers, we have a tendency to devise for the prolonged scurry when rising for at the present time, so a minimum amount of refactoring is wished to liberate scenarios which are prone to arise down the road.

An imaginary three-screened device
An imaginary instrument with 2 folds and 3 screens

Now not like CSS, JavaScript has the ideas of arrays, loops and conditionals which win the mapping between the Window Segments Enumeration API and a instrument with N hiss regions extra recount. For the imaginary instrument illustrated above, when the browser is spanned across all 3 hiss regions, calling the getWindowSegments() device will return an array of three DOMRects and using straight forward language primitives admire a loop or the built-in array ideas it is possible you’ll presumably presumably also be taught extra about how the hiss regions are configured (e.g. are all masks of the the same width?, and so on.)

In CSS, the most modern notion is to simply add contemporary values to the masks-spanning media feature representing contemporary masks topologies.

Originate bettering your web sites for foldable experiences at the present time

The CSS masks-spanning media feature and the Window Segment Enumeration API are on hand in the back of an experimental flag, it is possible you’ll presumably presumably also enable them at edge://flags/#enable-experimental-web-platform-substances.

Initiating in Microsoft Edge 86, web developers can exhaust Microsoft Edge DevTools to emulate twin-masks & foldable gadgets on Windows and Mac desktop platforms. Alternatively, it is possible you’ll presumably presumably also win and set up the contemporary Floor Duo emulator preview (version 2020.806.1 or more moderen) to test and debug using the built-in Edge browser after enabling experimental platform substances flag.

Both the JavaScript Window Segments Enumeration API and the CSS masks-spanning media substances are on hand as Initiating assign Trials, where it is possible you’ll presumably presumably also develop tokens and safely experiment with these contemporary primitives in manufacturing in alternate for offering us with suggestions in regards to the APIs. Signal in for an Initiating assign Trial whereas you’re attracted to attempting out out these APIs!

The road forward

These APIs are on hand for you to experiment with at the present time after many iterations and enhancements with the collaboration of the Chromium challenge, Google, Intel, W3C’s CSSWG, 2d-masks WG and loads of others.

We luxuriate in contributed both the CSS and JavaScript primitives for desktop platforms to the Chromium commence-source challenge and now the DevTools’ foldable and twin-masks gadgets emulation is on hand now no longer qualified in Edge, but additionally in Chrome and almost today in assorted Chromium-basically based totally browsers. We are at the second engaged on upstreaming the Android implementation so all Chromium-basically based totally browsers on Android OS can make stronger web developers handing over interesting contemporary experiences for this versatile instrument class.

For fogeys that also can luxuriate in suggestions about both with out a doubt one of the important APIs, please speak us by opening a downside on GitHub or alternatively it is possible you’ll presumably presumably also attain out to us on Twitter (@_zouhir or @MSEdgeDev).

– Zouhir Chahoud, Program Supervisor

– Daniel Libby, Most predominant Blueprint Engineering Supervisor

Read More

Leave A Reply

Your email address will not be published.