Cyber Week

Save big!

All courses under $5 - for a limited time!

Code has been added to clipboard!

iframe HTML Tag

Reading time 2 min
Published Feb 27, 2019
Updated Oct 1, 2019

iframe HTML: Main Tips

  • An inline frame renders using <iframe> tag.
  • A document can be embedded into the current document using an inline frame.

Usage of iframe

<iframe> HTML is an inline frame. It embeds one page into another.

Look at the iframe example below, showing its usage together with src property:

Example
<iframe src="https://cdn.bitdegree.org/learn/test-iframe.htm" width="90%" height="300px"></iframe>

Attributes to Use With iframe

height

It defines the height of an inline frame in pixels (px).

Example
<iframe src="https://cdn.bitdegree.org/learn/test-iframe.htm" width="90%" height="300px"></iframe>

name

It sets a name value for an inline frame.

Example
<iframe src="https://cdn.bitdegree.org/learn/test-iframe.htm" name="iframe_tutorial"></iframe>

sandbox

It defines constraints, governing the contents of an inline frame.

Example
<iframe src="https://cdn.bitdegree.org/learn/test-iframe.htm" sandbox></iframe>

src

It defines the link to a content, displayed in the inline frame.

Example
<iframe src="https://cdn.bitdegree.org/learn/test-iframe.htm" width="90%" height="300px"></iframe>

srcdoc

It specifies content of HTML nature to be displayed as the content in an inline frame.

Example
<iframe srcdoc="Hello from srcdoc!" src="https://www.bitdegree.org/"></iframe>

width

The iframe width property sets the width of an inline frame.

Example
<iframe src="https://cdn.bitdegree.org/learn/test-iframe.htm" width="90%" height="300px"></iframe>

Deprecated Attributes

align

It sets the alignment information for the inline frame. Not supported in HTML5.

Instead, use CSS float property. Learn how in the CSS Layout Float and Clear
tutorial.

Example
<!-- Renders a left aligned inline frame. -->
<iframe src="https://www.bitdegree.org/" width="250" height="250" align="left"></iframe>

frameborder

It sets the visibility of frame border to on(0) or off(1). Not supported in HTML5.

Use CSS border property instead. Learn how in the CSS Borders tutorial.

Example
<!-- Frameborder will not be visible. -->
<iframe src="https://www.bitdegree.org/" width="350" height="350" frameborder="0"></iframe>

longdesc

It specifies a document link that contains long description for the inline frame. Not supported in HTML5.

Example
<iframe src="https://www.bitdegree.org/" width="150" height="150" longdesc="data.txt"></iframe>

marginheight

It sets margin values for top and bottom of the content in an inline frame. Not supported in HTML5.

Instead, use CSS padding property. Learn how in the CSS Padding tutorial.

Example
<iframe src="https://www.bitdegree.org/" marginheight="20" width="100"></iframe>

marginwidth

It sets margin values for left and right of the content in an inline frame. Not supported in HTML5.

Apply the CSS padding property instead.

Example
<iframe src="https://www.bitdegree.org/" marginwidth="30"></iframe>

scrolling

It changes permissions of scrolling. Not supported in HTML5.

Example
<iframe src="https://www.bitdegree.org/" width="400" height="400" scrolling="yes"></iframe>

Browser support

Browser image
Chrome
1+
Browser image
Edge
All
Browser image
Firefox
All
Browser image
IE
All
Browser image
Opera
All
Browser image
Safari
All

Mobile browser support

Browser image
Chrome
All
Browser image
Firefox
All
Browser image
Opera
All
Browser image
Safari
All