In this article, we’re going to explore HTML Iframes and how to use them with practical examples. An iframe, short for Inline Frame, is like a little window embedded within your web page where you can display another web page. It’s like having a mini-browser within your main webpage, complete with scrollbars and borders.
Here’s a simplified breakdown:
What’s an Iframe? It’s a way to put one web page inside another web page. Imagine it as a picture-in-picture for websites.
Why Use Iframes? They’re handy when you want to show a different webpage within your current one. It’s like a sneak peek or a related article embedded right on your page.
How to Name an Iframe: We use the name attribute with the <iframe> element. This name can also be used to interact with the iframe content using JavaScript.
Setting the Source (src): To tell the iframe which webpage to display, you use the src attribute. It’s like telling it where to go.
<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.
<!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>
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.
<!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>
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.
<!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>
Example: This example describes the HTML iframe Tag by specifying the border style.
<!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>
Not a member yet? Register now
Are you a member? Login now