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

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

Mobile browser support

Chrome
All
Firefox
All
Opera
All
Safari
All
Basics
Introduction
Syntax
Editors
Basic Examples
Head Section
<!DOCTYPE>
Tags and Elements
Semantic Elements
Tags Reference
Attributes
Comments
Block and Inline Elements
Forms
Form Elements
Input
Responsive Web Design
Inline Scripts
Uniform Resource Locator
Redirect
XHTML
Geolocation
Drag and Drop
Local Storage
Web Workers
Server-Sent Events
Character Encoding
Text Formatting
Quotation and Citation Elements
Headings
Paragraphs
Links
Tables
Lists
Symbols
Space
Tab
Styles
Computer Code
Layout
Classes
Colors
Images
iframes
Audio Player
Video Player
YouTube Videos
Multimedia
Canvas
SVG
<!-- -->
<a>
<abbr>
<acronym> DEPRECATED
<address>
<applet> DEPRECATED
<article>
<aside>
<audio>
<b>
<base>
<basefont> DEPRECATED
<bdi>
<bdo>
<big> DEPRECATED
<blink> DEPRECATED
<blockquote>
<body>
<br>
<button>
<canvas>
<caption>
<center> DEPRECATED
<cite>
<code>
<col>
<colgroup>
<datalist>
<dd>
<del>
<details>
<dfn>
<dialog>
<dir> DEPRECATED
<div>
<dl>
<dt>
<em>
<embed>
<fieldset>
<figcaption>
<figure>
<font> DEPRECATED
<footer>
<form>
<frame> DEPRECATED
<frameset> DEPRECATED
<h1> – <h6>
<head>
<header>
<hr>
<html>
<i>
<iframe>
<img>
<input>
<ins>
<kbd>
<keygen> DEPRECATED
<label>
<legend>
<li>
<link>
<main>
<map>
<mark>
<menu>
<menuitem> DEPRECATED
<meta>
<meter>
<nav>
<noframes> DEPRECATED
<noscript>
<object>
<ol>
<optgroup>
<option>
<output>
<p>
<param>
<pre>
<progress>
<q>
<rp>
<rt>
<ruby>
<s>
<samp>
<script>
<section>
<select>
<small>
<source>
<span>
<strike> DEPRECATED
<strong>
<style>
<sub>
<summary>
<sup>
<table>
<tbody>
<td>
<tfoot>
<th>
<thead>
<time>
<title>
<tr>
<track>
<tt> DEPRECATED
<u>
<ul>
<var>
<video>
<wbr>