HTML Iframes - GeeksforGeeks

17 Mar, 2022
In this article, we will know HTML Iframes, their implementation through the examples. The iframe in HTML stands for Inline Frame. The ” iframe ” tag defines a rectangular region within the document in which the browser can display a separate document, including scrollbars and borders. An inline frame is used to embed another document within the current HTML document. The HTML iframe name attribute is used to specify a reference for an <Iframe> element. The name attribute is also used as a reference to the elements in JavaScript. The iframe is basically used to show a webpage inside the current web page. The ‘ src ‘ attribute is used to specify the URL of the document that occupies the iframe.
Syntax:
<iframe src="URL" title="description"></iframe>
Attributes value: It contains a single value URL that specifies the URL of the document that is embedded in the iframe. There are two types of URL links which are listed below:
Absolute URL: It points to another webpage.
Relative URL: It points to other files of the same web page.
Example: This example illustrates the use of an iframe tag which is used to display a webpage inside the current web page.
HTML
<!DOCTYPE html><html>  <head>    <title>HTML iframe Tag</title></head>  <body style="text-align: center">    <h1>GeeksforGeeks</h1>    <h2>HTML iframe Tag</h2>    <iframe src="https://ide.geeksforgeeks.org/index.php"             height="200"             width="400">              </iframe></body>  </html>
Output:
HTML iframe tag
Accepted Attribute: The following attributes can be used with the <iframe> tag in HTML.
HTML <iframe> allow Attribute
HTML <iframe> allowfullscreen attribute
HTML <iframe> allowpaymentrequest attribute
HTML <iframe> height attribute
HTML <iframe> width attribute
HTML <iframe> loading attribute
HTML <iframe> scrolling attribute
HTML <iframe> name attribute
HTML <iframe> referrerpolicy attribute
HTML <iframe> sandbox attribute
HTML <iframe> src attribute
HTML <iframe> srcdoc attribute
Below few of the attributes examples are given:
Height and Width: The height and width attributes are used to specify the size of the iframe. The attribute values are specified in pixels by default, but they can also be specified in percentages like ” 80% “.
Example: This example describes the HTML iframe Tag by setting the width & height of the iframe.
HTML
<!DOCTYPE html><html>  <body>    <h1>GeeksforGeeks</h1>    <h2>HTML iframe Tag</h2>    <p>Content goes here</p>      <iframe src="https://ide.geeksforgeeks.org/tryit.php"             height="300"             width="400">     </iframe></body>  </html>
Output:
Setting the width & height of HTML iframe
Removing Border: By default, iframe has a border around it. To remove the border, we must use the style attribute and use the CSS border property.
Example: This example describes the HTML iframe Tag where the border property is set as none.
HTML
<!DOCTYPE html><html>  <body>    <h1>GeeksforGeeks</h1>    <h2>HTML iframe Tag</h2>    <p>Content goes here</p>      <iframe src="https://ide.geeksforgeeks.org/tryit.php"             height="300"             width="400"             style="border: none">     </iframe></body>  </html>
Output:
HTML iframe with no border
Border Style: Changing the size, style, and color of the Iframe’s border:
Example: This example describes the HTML iframe Tag by specifying the border style.
HTML
<!DOCTYPE html><html>  <body>    <p>Content goes here</p>    <iframe src="https://ide.geeksforgeeks.org/tryit.php"             height="300"             width="400"             style="border: 4px solid orange">     </iframe></body>  </html>
Output:
HTML iframe with border style
Link: An iframe can be used as the target frame for a link. The target attribute of the link must refer to the name attribute of the iframe.
Example: This example describes the HTML iframe Tag by using the target frame for a link.
HTML
<!DOCTYPE html><html>  <body>    <h1>GeeksforGeeks</h1>    <h2>HTML iframe Tag</h2>    <p>Click the link text</p>    <iframe height="300"             width="350"             src="https://media.geeksforgeeks.org/wp-content/uploads/20210910170539/gfg-221x300.png"            name="iframe_a">     </iframe>    <p><a href="https://ide.geeksforgeeks.org/tryit.php"            target="iframe_a">        GeeksforGeeks IDE        </a>     </p>    </body>  </html>
Output:
HTML iframe with a link tag
Supported Browsers: 
Google Chrome 93.0
Internet Explorer 11.0
Firefox 92.0
Microsoft Edge 93.0
Opera 78.0
Safari 14.1
Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.
ghoshsuman0129
bhaskargeeksforgeeks
HTML-Tags
HTML
Technical Scripter
HTML
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Top 10 Projects For Beginners To Practice HTML and CSS Skills
How to insert spaces/tabs in text using HTML/CSS?
How to set the default value for an HTML <select> element ?
How to update Node.js and NPM to next version ?
How to set input type date in dd-mm-yyyy format using HTML ?
How to Insert Form Data into Database using PHP ?
Hide or show elements in HTML using display property
REST API (Introduction)
Types of CSS (Cascading Style Sheet)
CSS to put icon inside an input element in a form