HTML
π What is <iframe> ?
The <iframe> (inline frame) is used to embed another web page inside a web page.
π In other words :
- You open a separate page inside your page
- It works like a βpage within a pageβ
Examples:
HTML
<iframe src="https://example.com"></iframe>
πΉ Important attributes :
- src β The URL of the page to display
- title β A description for accessibility (very important!)
- π These two attributes are generally used for styling with CSS.
π Using the title attribute is considered a best practice.
π Setting Height and Width
You can adjust the size of the iframe:
Using HTML:
HTML
<iframe src="demo.html" height="200" width="300"></iframe>
Using CSS:
HTML
<iframe src="demo.html" style="height:200px; width:300px;"></iframe>
π¨ Border (Frame) Settings
By default, iframes have a border.
To remove it:
HTML
<iframe src="demo.html" style="border: none;"></iframe>
To customize it:
HTML
<iframe src="demo.html" style="border: 2px solid red;"></iframe>
π Opening Links Inside an Iframe
You can make links open inside the iframe instead of changing the main page.
How to do it?
1. Give the iframe a name:
HTML
<iframe name="frame1"></iframe>
2. Use target in the link:
HTML
<a href="https://example.com" target="frame1">Open</a>
π Result:
- Clicking the link does not change the main page
- The content loads inside the iframe
π§ Summary (Key Points)
-
</iframe>β embeds another page inside your page - src β specifies the content to display
- title β important for accessibility
- height & width β control the size
- border β can be removed or customized
- name + target β allows links to open inside the iframe
