Skip to content

Commit 5910ff2

Browse files
authored
Update responsive-iframes-explainer.md (w3c#12211)
1 parent 0e43e41 commit 5910ff2

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

css-sizing-4/responsive-iframes-explainer.md

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@
55
[Iframes]([url](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/iframe)) are very useful for sandboxing web content into different documents. The options currently available are:
66
1. A [same-origin]([url](https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy)) iframe, which provides full style &
77
layout isolation, and by-default script isolation. This prevents the parent and child documents from accidentally interfering with each other.
8-
2. A cross-origin iframe, which additionally provides robust security against untrusted embedders or embedees.
8+
2. A cross-origin iframe, which additionally provides robust security and privacy against untrusted embedders or embedees.
99

1010
In addition, iframes participate in the layout of the parent document, via the style and layout of their owning `<iframe>` element.
11-
However, unlike other HTML elements such as `<div>`, iframe elements do not have the ability to support *responsive layout*, i.e. size themselves automatically to contain the [natural dimensions]([url](https://drafts.csswg.org/css-images-3/#natural-dimensions)) of the contents of the iframe. Instead, browser automatically add scrollbars to ifrmaes as necessary, so that users can access the content.
11+
However, unlike other HTML elements such as `<div>`, iframe elements do not have the ability to support *responsive layout*, i.e. size themselves automatically to contain the [natural dimensions]([url](https://drafts.csswg.org/css-images-3/#natural-dimensions)) of the contents of the iframe. Instead, browsers automatically add scrollbars to iframes as necessary, so that users can access the content.
1212

1313
This is a problem:
1414
* From a user's perspective, iframe scrollbars are a worse UX in cases where the iframe contents are important to them and can fit reasonably in the visible viewport without these additional scrollbars.
15-
* From a developer's perspective, they are forced to use script to communicate natural dimensions, in order to help the user have better UX without scrollbars.
15+
* From a developer's perspective, they are forced to use non-trivial script to communicate natural dimensions across frames in order to help the user have better UX without scrollbars.
1616

17-
Embedded SVG documents already support responsive layout. *Responsive iframes* add responsive layout to iframes, as long as the embedding and embedded document both opt into do so. This allows supporting responsive layout without losing any of the advantages of iframes in (1) and (2) above.
17+
Embedded SVG documents already support responsive layout. *Responsive iframes* add responsive layout to iframes, as long as the embedding and embedded document both opt into do so, thus providing support for responsive layout without losing any of the advantages of iframes in (1) and (2) above.
1818

1919
## Use cases
2020

2121
Use cases include:
2222
* 3P comment widgets ([example]([url](https://github.com/whatwg/html/issues/555#issuecomment-177836009)))
23-
* Embedding self-contained worked examples in teaching UI ([example]([url](https://browser.engineering/layout.html))).
23+
* Embedding self-contained worked examples in teaching UI ([example]([url](https://browser.engineering/layout.html)))
2424

2525
In general, there is a lot of demand for this feature, as evidenced by:
2626
* [Stack overflow]([url](https://stackoverflow.com/search?q=resize+iframe))
@@ -29,23 +29,22 @@ In general, there is a lot of demand for this feature, as evidenced by:
2929

3030
## Solution
3131

32+
The embedding document opts in via the `contain-intrinsic-size: from-element` CSS property on the `<iframe>` element, and the embedded document opts in via a new `<meta name="responsive-embedded-sizing">` tag.
3233

33-
The embedding document does so via the `contain-intrinsic-size: from-element` CSS property on the `<iframe>` element, and the embedded document via a new `<meta>` tag with name `responsive-embedded-sizing`.
34-
35-
When both are set, then at the time the `load` event on the embedded document fires, the embedding document is notified with the new [natural height]([url](https://drafts.csswg.org/css-images-3/#natural-height)) of the embedded (iframe) document. This height is then taken into account in the final size of the `<iframe>` element, along with other constraints specified by the HTML and CSS of the embedding document. Subsequent changes to content, styling or layout fo the embedded document do not affect the `<iframe>` sizing.
34+
When the meta tag is present at the time the `load` event on the embedded document fires, the embedding document is notified with the new [natural height]([url](https://drafts.csswg.org/css-images-3/#natural-height)) of the embedded (iframe) document. If `contain-intrinsic-size` is set on the `<iframe>` element, it takes this heigh into consideration in the same way as any other replaced element's layout, along with other constraints specified by the HTML and CSS of the embedding document. Subsequent changes to content, styling or layout fo the embedded document do not affect the `<iframe>` sizing.
3635

3736
The double opt-in preserves:
38-
* Backward compatibility for existing content.
39-
* Privacy and security guarantees of cross-origin content.
37+
* Backward compatibility for existing content
38+
* Privacy and security guarantees of cross-origin content
4039

4140
The "one-shot" sizing to natural dimensions avoids:
42-
* Performance issues and CLS due to changing iframe sizing. (To further mitigatge performance risks, limitations on levels of `<iframe>` nesting may be imposed.)
43-
* Potential infinite layout loops.
41+
* Performance issues and CLS due to changing iframe sizing (To further mitigatge performance risks, limitations on levels of `<iframe>` nesting may be imposed.)
42+
* Potential infinite layout loops
4443

4544
## Future extensions
4645

4746
A JavaScript API could be added in the future that would allow embedded documents to request relayout in their embedding document context.
4847

4948
## Privacy and security
5049

51-
Information about the contents of a cross-origin iframe can be exfiltrated by an embedding malicious document that observes the laid-out size of the iframe. This can be mitigated through use of the the `X-Frame-Options` HTTP header to allow embedding into only trusted embedding documents, plus the `responsive-embedded-sizing` `<meta>` tag to further opt into responsive layout. Additional restrictions could be put in place through contents of the `<meta>` tag that would restrict to only explicitly allowed origins.
50+
Information about the contents of a cross-origin iframe can be exfiltrated by embedding it in a malicious document that observes the laid-out size of the iframe. This can be mitigated through use of the the `X-Frame-Options` HTTP header to allow embedding into only trusted embedding documents, plus the `responsive-embedded-sizing` `<meta>` tag to further opt into responsive layout. Additional restrictions could be put in place through contents of the `<meta>` tag that would restrict to only explicitly allowed origins.

0 commit comments

Comments
 (0)