HTML <iframe> tagS2C Home « HTML <iframe> tag
Definition
The <iframe> tag is used to define nested browsing context such as an inline frame that holds another document.
Pre HTML5, some text could be added between the opening and closing <iframe> tags as a fallback for when the <iframe> tag wasn't supported in a browser, this is no longer allowed and will cause an error when validating a HTML5 document.
Example
The example below is embedded in the page so you can see an inline frame in real time and is a snapshot of the jQuery Reference - Attributes & Properties - .position() method taken from another of my tutorial sites.
The following html code is used to render an iframe inline in real time.
<iframe src="https://learnjavascript.co.uk/jq/reference/ap/position2.html" width="300" height="300">
</iframe>
Attributes
The following attributes can be used with the <iframe> tag.
| Attribute | Value | Description | Example |
|---|---|---|---|
allow | text | Determines the container policy that will be used when the feature policy for a Document in the iframe's nested browsing context is initialized. | |
allow | true false | Specifies that Document objects in the iframe tag's browsing context are to be allowed to use request |
|
allow | true false | Specifies that Document objects in the iframe tag's nested browsing context will be initialized with a feature policy which allows the payment feature to be used to make payment requests from any origin. | |
height | Non-negative positive integer gt 0 | Specifies the height of the iframe in pixels. | |
name | text | Specifies a name to assign to an iframe which can be targeted from another frame or HTML tag attributes. | |
referrerpolicy | Specifies how much referrer information is sent. | | |
| no-referrer | No referrer information is to be sent. | ||
| no-referrer-when-downgrade | Full referrer URL stripped of referrerURL and current URL and untrustworthy URLs.. | ||
| origin | Only the ASCII serialization of the request’s referrerURL is sent as referrer information when making both same-origin-referrer requests and cross-origin-referrer requests. | ||
| origin-when-cross-origin | Full referrerURL is sent as referrer information when making same-origin-referrer requests and only the ASCII serialization of the origin of the request’s referrerURL is sent as referrer information when making cross-origin-referrer requests. | ||
| same-origin | Full referrerURL sent as referrer information when making same-origin-referrer requests. | ||
| strict-origin | ASCII serialization of origin of the referrerURL whose referrerURL and current URL are both potentially trustworthy URLs, or whose referrerURL is a non-potentially trustworthy URL. | ||
| strict-origin-when-cross-origin | Full referrerURL sent as referrer information for same-origin-referrer requests and only the ASCII serialization of the origin of the request’s referrerURL when making cross-origin-referrer requests. | ||
| unsafe-url | Full referrerURL sent along for both same-origin-referrer requests and cross-origin-referrer requests. | ||
sandbox | Specifies a space separated set of restrictions allowed for the iframe - if left empty all restrictions apply. | | |
| allow-forms | Allow form submission. | ||
| allow-pointer-lock | Enables pointer lock. | ||
| allow-popups | Allow popup windows. | ||
| allow-same-origin | Treats content as from same origin. | ||
| allow-scripts | Allow script execution excluding popups. | ||
| allow-top-navigation | Allow content to load to the top-level browsing context. | ||
src | url | Specifies the location of the resource to display in the iframe. | |
srcdoc | url | Specifies the HTML content of the page to display in the iframe. Generally used with the sandbox attribute to provide an additional layer of security. |
|
width | Non-negative positive integer gt 0 | Specifies the width of the iframe in pixels. | |
| Attribute | Description | Example |
|---|---|---|
| Common | ||
class | Specifies a classname for the element allowing you to apply the style of the predefined class to the content. | |
id | Specifies a unique id for the element allowing you to apply the style of the predefined id to the content. | |
style | Specifies an inline style for the element allowing you to apply the style to the contentt. | |
title | Specifies an inline style for the element allowing you to apply the style to the content. | |
| Keyboard | ||
accesskey | Specifies a keyboard shortcut to associate with the element. | |
tabindex | Specifies a tab order for the element. | |
| Language | ||
dir | Specifies the directional flow of the content. | |
lang | Specifies a language code for the content of the element. | |
spell | Specifies an inline style for the element allowing you to apply the style to the contentt. | |
translate | Specifies an inline style for the element allowing you to apply the style to the content. | |
| Miscellaneous | ||
content | Specifies whether the content of the element is editable. | |
draggable | Specifies whether the element is draggable. | |
hidden | Specifies whether the element is not yet, or no longer, relevant. | |
| Attribute | Description | Example |
|---|---|---|
| Document Element | ||
oncopy | The script to be run when the user copies the content of an element. | |
oncut | The script to be run when the user cuts the content of an element. | |
onpaste | The script to be run when the user pastes some content into an element. | |
| Drag and Drop | ||
ondrag | The script to be run when an element is dragged. | |
ondragend | The script to be run when an element has stopped being dragged. | |
ondrag | The script to be run when an element has been dragged to a valid drop target. | |
ondrag | The script to be run when an element leaves a valid drop target. | |
ondragover | The script to be run when an element is being dragged over a valid drop target. | |
ondrag | The script to be run at the start of a drag operation. | |
ondrop | The script to be run when a dragged element is being dropped. | |
| Form | ||
onblur | The script to be run when the element loses focus. | |
onchange | The script to be run when object changed and attempt to leave field. | |
oncontext | The script to be run when a context menu is triggered. | |
onfocus | The script to be run when the element gets focus. | |
oninput | The script to be run when an element gets user input. | |
oninvalid | The script to be run when an element is invalid. | |
onreset | The script to be run when a dragged element is being dropped. | |
onselect | The script to be run when some or all of the contents of an object are selected. | |
onsubmit | The script to be run when a form is submitted. | |
| Keyboard | ||
onkeydown | The script to be run when an element is in focus and keyboard key is pressed down. | |
onkeypress | The script to be run when an element is in focus and keyboard key is pressed down and released. | |
onkeyup | The script to be run when an element is in focus and keyboard key is released. | |
| Media | ||
onabort | The script code to be run on abort. | |
oncanplay | The script to be run when a file has buffered enough so it is ready to start playing. | |
oncanplay | The script to be run when a file can be played all the way to the end without further need of buffering. | |
oncue | The script to be run when the cue changes when using the track element. |
|
onduration | The script to be run when the length of the media is changed. | |
onemptied | The script to be run when a media resource element suddenly becomes empty, usually due to an error. | |
onended | The script to be run when the media has reach the end. | |
onloaded | The script to be run when media data is loaded and playback can start. | |
onloaded | The script to be run when metadata has been loaded. | |
onload | The script to be run whenthe media resource has started loading. | |
onpause | The script to be run when the media resource has been paused. | |
onplay | The script to be run when the media resource starts playback. | |
onplaying | The script to be run when when playback has already begun. | |
onprogress | The script to be run when the browser is fetching the media data. | |
onrate | The script to be run when the playback rate changes. | |
onseeked | The script to be run when the seeking attribute is set to false indicating that seeking has finished. | |
onseeking | The script to be run when the seeking attribute is set to true indicating that seeking is currently active. | |
onstalled | The script to be run when the browser is unable to continue fetching media data. | |
onsuspend | The script to be run when media data has stopped before being completely loaded. | |
ontime | The script to be run when the media resources current playback position has changed. | |
onvolume | The script to be run when the volume has changed or been muted. | |
onwaiting | The script to be run when the media resource has paused but is expected to resume. | |
| Mouse | ||
onclick | The script to be run when when a mouse is clicked on an element. | |
ondblclick | The script to be run when a mouse is double clicked on an element. | |
onmouse | The script to be run when he mouse button is pressed down while the cursor is over an element. | |
onmouse | The script to be run when the mouse button is moved. | |
onmouseout | The script to be run when the mouse cursor moves off an element. | |
onmouse | The script to be run when the mouse cursor moves over an element. | |
onmouseup | The script to be run when the mouse button is released while the cursor is over the element. | |
onwheel | The script to be run when the mouse wheel rolls up or down over an element. | |
| Scroll | ||
onscroll | The script code to be run when the scrollbar of an element is being scrolled. | |
| Window - NONE | ||