HTML Iframes - Javatpoint
HTML Iframes - Javatpoint
HTML iframes
HTML Iframe is used to display a nested webpage (a webpage within a webpage). The HTML <iframe>
tag defines an inline frame, hence it is also called as an Inline frame.
An HTML iframe embeds another document within the current HTML document in the rectangular
region.
The webpage content and iframe contents can interact with each other using JavaScript.
Iframe Syntax
<iframe src="URL"></iframe>
Here, "src" attribute specifies the web address (URL) of the inline frame page.
https://www.javatpoint.com/html-iframes 2/13
5/2/24, 4:24 PM HTML Iframes - javatpoint
Example: (Pixels)
<!DOCTYPE html>
<html>
<body>
<h2>HTML Iframes example</h2>
<p>Use the height and width attributes to specify the size of the iframe:</p>
<iframe src="https://www.javatpoint.com/" height="300" width="400"></iframe>
</body>
</html>
Test it Now
Example: (Percentage)
<!DOCTYPE html>
<html>
<body>
<h2>HTML Iframes</h2>
<p>You can use the height and width attributes to specify the size of the iframe:</p>
<iframe src="https://www.javatpoint.com/" height="50%" width="70%"></iframe>
</body>
</html>
Test it Now
You can also use CSS to set the height and width of the iframe.
Example:
<!DOCTYPE html>
https://www.javatpoint.com/html-iframes 3/13
5/2/24, 4:24 PM HTML Iframes - javatpoint
<html>
<body>
<h2>HTML Iframes</h2>
<p>Use the CSS height and width properties to specify the size of the iframe:</p>
<iframe src="https://www.javatpoint.com/" style="height:300px;width:400px"></iframe>
</body>
</html>
Test it Now
Example:
<!DOCTYPE html>
<html>
<body>
<h2>Remove the Iframe Border</h2>
<p>This iframe example doesn't have any border</p>
<iframe src="https://www.javatpoint.com/" style="border:none;"></iframe>
</body>
</html>
Test it Now
You can also change the size, color, style of the iframe's border.
Example:
<!DOCTYPE html>
<html>
<body>
<h2>Custom Iframe Border</h2>
https://www.javatpoint.com/html-iframes 4/13
5/2/24, 4:24 PM HTML Iframes - javatpoint
Test it Now
Example:
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Test it Now
https://www.javatpoint.com/html-iframes 5/13
5/2/24, 4:24 PM HTML Iframes - javatpoint
Output
<!DOCTYPE html>
<html>
<head>
<style>
p{ font-size: 50px;
color: red;}
</style>
</head>
<body style="background-color: #c7f15e;">
<p>This is a link below the ifarme click on link to open new iframe. </p>
</body>
</html>
https://www.javatpoint.com/html-iframes 6/13
5/2/24, 4:24 PM HTML Iframes - javatpoint
Example:
Test it Now
Output:
https://www.javatpoint.com/html-iframes 7/13
5/2/24, 4:24 PM HTML Iframes - javatpoint
Attributes of <iframe>
height Pixels It defines the height of the embedded iframe, and the default
height is 150 px.
https://www.javatpoint.com/html-iframes 8/13
5/2/24, 4:24 PM HTML Iframes - javatpoint
name text It gives the name to the iframe. The name attribute is important if
you want to create a link in one frame.
Width Pixels It defines the width of embedded frame, and default width is 300
px.
src URL The src attribute is used to give the path name or file name which
content to be loaded into iframe.
sandbox This attribute is used to apply extra restrictions for the content of
the frame
allow-forms It allows submission of the form if this keyword is not used then
form submission is blocked.
allow- It will enable popups, and if not applied then no popup will open.
popups
allow-same- If this keyword is used then the embedded resource will be treated
origin as downloaded from the same source.
srcdoc The srcdoc attribute is used to show the HTML content in the inline
iframe. It overrides the src attribute (if a browser supports).
scrolling It indicates that browser should provide a scroll bar for the iframe
or not. (Not supported in HTML5)
auto Scrollbar only shows if the content of iframe is larger than its
dimensions.
← Prev Next →
https://www.javatpoint.com/html-iframes 9/13