<iframe>: 인라인 프레임 요소
<iframe> 요소는 중첩 브라우징 맥락을 나타내는 요소로, 현재 문서 안에 다른 HTML 페이지를 삽입합니다.
각각의 브라우징 맥락은 완전한 문서 환경이므로, 페이지에
<iframe>을 추가할 때마다 메모리 및 기타 컴퓨터 자원 사용량이 늘어납니다. 이론상으로는 원하는 만큼
<iframe>을 사용할 수 있지만, 성능 문제가 없는지 확인하세요.
이 요소는 전역 특성을 포함합니다.
- Specifies a feature policy for the
<iframe>. See the article Privacy, permissions, and information security for details on security issues and how
<iframe>works with Feature Policy to keep systems safe.
- Set to
<iframe>can activate fullscreen mode by calling the
This attribute is considered a legacy attribute and redefined as
- Set to
trueif a cross-origin
<iframe>should be allowed to invoke the Payment Request API.
This attribute is considered a legacy attribute and redefined as
- A Content Security Policy enforced for the embedded resource. See
HTMLIFrameElement.csp(en-US) for details.
- The height of the frame in CSS pixels. Default is
- The download priority of the resource in the
srcattribute. Allowed values:
- No preference. The browser uses its own heuristics to decide the priority of the resource.
- The resource should be downloaded before other lower-priority page resources.
- The resource should be downloaded after other higher-priority page resources.
- Indicates how the browser should load the iframe:
eager: Load the iframe immediately, regardless if it is outside the visible viewport (this is the default value).
lazy: Defer loading of the iframe until it reaches a calculated distance from the viewport, as defined by the browser.
- A targetable name for the embedded browsing context. This can be used in the
targetattribute of the
formtargetattribute of the
<button>elements; or the
windowNameparameter in the
- Indicates which referrer to send when fetching the frame's resource:
Refererheader will not be sent.
Refererheader will not be sent to origins without TLS (HTTPS).
origin: The sent referrer will be limited to the origin of the referring page: its scheme, host (en-US), and port (en-US).
origin-when-cross-origin: The referrer sent to other origins will be limited to the scheme, the host, and the port. Navigations on the same origin will still include the path.
same-origin: A referrer will be sent for same origin (en-US), but cross-origin requests will contain no referrer information.
strict-origin: Only send the origin of the document as the referrer when the protocol security level stays the same (HTTPS→HTTPS), but don't send it to a less secure destination (HTTPS→HTTP).
strict-origin-when-cross-origin: Send a full URL when performing a same-origin request, only send the origin when the protocol security level stays the same (HTTPS→HTTPS), and send no header to a less secure destination (HTTPS→HTTP).
unsafe-url: The referrer will include the origin and the path (but not the fragment, password, or username). This value is unsafe, because it leaks origins and paths from TLS-protected resources to insecure origins.
- Applies extra restrictions to the content in the frame. The value of the attribute can either be empty to apply all restrictions, or space-separated tokens to lift particular restrictions:
Notes about sandboxing:
allow-downloads-without-user-activationExperimental : Allows for downloads to occur without a gesture from the user.
allow-forms: Allows the resource to submit forms. If this keyword is not used, form submission is blocked.
allow-modals: Lets the resource open modal windows.
allow-orientation-lock: Lets the resource lock the screen orientation.
allow-pointer-lock: Lets the resource use the Pointer Lock API.
allow-popups: Allows popups (such as
showModalDialog()). If this keyword is not used, the popup will silently fail to open.
allow-popups-to-escape-sandbox: Lets the sandboxed document open new windows without those windows inheriting the sandboxing. For example, this can safely sandbox an advertisement without forcing the same restrictions upon the page the ad links to.
allow-presentation: Lets the resource start a presentation session.
allow-same-origin: If this token is not used, the resource is treated as being from a special origin that always fails the same-origin policy (en-US).
allow-scripts: Lets the resource run scripts (but not create popup windows).
allow-storage-access-by-user-activationExperimental : Lets the resource request access to the parent's storage capabilities with the Storage Access API.
allow-top-navigation: Lets the resource navigate the top-level browsing context (the one named
allow-top-navigation-by-user-activation: Lets the resource navigate the top-level browsing context, but only if initiated by a user gesture.
- When the embedded document has the same origin as the embedding page, it is strongly discouraged to use both
allow-same-origin, as that lets the embedded document remove the
sandboxattribute — making it no more secure than not using the
sandboxattribute at all.
- Sandboxing is useless if the attacker can display content outside a sandboxed
iframe— such as if the viewer opens the frame in a new tab. Such content should be also served from a separate origin to limit potential damage.
sandboxattribute is unsupported in Internet Explorer 9 and earlier.
- The URL of the page to embed. Use a value of
about:blankto embed an empty page that conforms to the same-origin policy. Also note that programatically removing an
<iframe>'s src attribute (e.g. via
about:blankto be loaded in the frame in Firefox (from version 65), Chromium-based browsers, and Safari/iOS.
- Inline HTML to embed, overriding the
srcattribute. If a browser does not support the
srcdocattribute, it will fall back to the URL in the
- The width of the frame in CSS pixels. Default is
These attributes are deprecated and may no longer be supported by all user agents. You should not use them in new content, and try to remove them from existing content.
alignDeprecated HTML4.01, Deprecated
- The alignment of this element with respect to the surrounding context.
- The value
1(the default) draws a border around this frame. The value
0removes the border around this frame, but you should instead use the CSS property
- A URL of a long description of the frame's content. Due to widespread misuse, this is not helpful for non-visual browsers.
- The amount of space in pixels between the frame's content and its top and bottom borders.
- The amount of space in pixels between the frame's content and its left and right borders.
- Indicates when the browser should provide a scrollbar for the frame:
auto: Only when the frame's content is larger than its dimensions.
yes: Always show a scrollbar.
no: Never show a scrollbar.
With the DOM
HTMLIFrameElement (en-US) object, scripts can access the
window object of the framed resource via the
contentWindow (en-US) property. The
contentDocument (en-US) property refers to the
document inside the
<iframe>, same as
From the inside of a frame, a script can get a reference to its parent window with
Script access to a frame's content is subject to the same-origin policy (en-US). Scripts cannot access most properties in other
window objects if the script was loaded from a different origin, including scripts inside a frame accessing the frame's parent. Cross-origin communication can be achieved using
<iframe> in action. After creating the frame, when the user clicks a button, its title is displayed in an alert.
<iframe src="https://mdn-samples.mozilla.org/snippets/html/iframe-simple-contents.html" title="iframe Example 1" width="400" height="300"> </iframe>
<iframe id="Example2" title="iframe Example 2" width="400" height="300" style="border:none" src="https://maps.google.com/maps?f=q&source=s_q&q=buenos+aires&sll=37.0625,-95.677068&sspn=38.638819,80.859375&t=h&hnear=Buenos+Aires,+Argentina&z=11&ll=-34.603723,-58.381593&output=embed"> </iframe>
|HTML Standard |
BCD tables only load in the browser