Open In App

HTML Iframes

Last Updated : 20 Mar, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

An iframe in HTML allows you to embed another HTML document within your current webpage. It’s like having a mini window that displays content from an external source. It supports various attributes for specifying dimensions, borders, scrolling, and more to customize the appearance and behaviour of the embedded content.

Syntax:

<iframe src="URL" title="description"></iframe>
  • The src attribute specifies the URL of the document you want to embed.
  • Iframes can include videos, maps, or entire web pages from other sources.

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:

URL

Descriptions

Absolute URL

It points to another webpage.

Relative URL

It points to other files of the same web page.

Supported Attributes:

AttributesDescription
allowSpecifies a set of extra restrictions on the content that can be loaded in an <iframe>.
allowfullscreenIndicates whether the <iframe> can be displayed in fullscreen mode.
allowpaymentrequestEnables payment requests for content inside the <iframe>.
heightSets the height of the <iframe> element.
widthSets the width of the <iframe> element.
loadingSpecifies how the content of the <iframe> should be loaded.
scrollingControls whether or not the <iframe> should have scrollbars.
name Specifies the name of the <iframe> for targeting its content or for referencing it in JavaScript.
referrerpolicySets the referrer policy for the <iframe> content.
sandboxSpecifies an extra set of restrictions for the content in the <iframe>.
srcSpecifies the URL of the document to embed in the <iframe>.
srcdocSpecifies the HTML content of the page to display in the <iframe>.

HTML Iframes Examples

Example 1: 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 example

HTML iframe tag

2. Using Height and Width attribute:

The height and width attributes are used to specify the size of the iframe. The attribute values are specified in pixels by default. You can use pixels or percentages (e.g., “80%”).

Example 2: 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

3. Removing Borders from Iframe

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 3: 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

4. Iframe Border Style

Changing the size, style, and color of the Iframe’s border.

Example 4: 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

5. Iframe Target in 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 5: 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 src=
"https://media.geeksforgeeks.org/wp-content/uploads/20210910170539/gfg-221x300.png"
            height="300"
            width="350" 
            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 1
  • Edge 12
  • Firefox 1
  • Opera 15
  • Safari 4


Like Article
Suggest improvement
Previous
HTML Block and Inline Elements
Next
HTML File Paths
Share your thoughts in the comments

Similar Reads

How to create Responsive iFrames using CSS ?
HTML | DOM HTML Object
HTML | <html> xmlns Attribute
Inline HTML Helper - HTML Helpers in ASP.NET MVC
How to return HTML or build HTML using JavaScript ?
How to convert html.slim to html.erb ?
How to include HTML code snippets in HTML ?
How to display HTML tags as plain text in HTML ?
What is the difference between <html lang="en'> and <html lang="en-US'> ?
HTML Course Structure of an HTML Document

聚圣源网咖起名京东通信易经取名字网站免费起名网前线任务3湖南卫视金鹰独播剧场枉费心机的意思游戏里女号起什么名字好高起名字大全男孩霸气起名肖姓马龙潭名字名字起名字有哪些双胎男宝起名大全大书库石小满男女孩诗经取名起名大全楚辞禁断介护鼠宝宝属火起名骂神宝典哈利波特全集下载赵姓女起名魔法种族大穿越缉毒警察李雄被剥皮碎骨女宝宝起名闫算命先生起名兔子起名大全可爱笔画8划的起名新生儿起名大全小名大全笔画8的字起名关雪盈免费周易取名起名大全软件淀粉肠小王子日销售额涨超10倍罗斯否认插足凯特王妃婚姻让美丽中国“从细节出发”清明节放假3天调休1天男孩疑遭霸凌 家长讨说法被踢出群国产伟哥去年销售近13亿网友建议重庆地铁不准乘客携带菜筐雅江山火三名扑火人员牺牲系谣言代拍被何赛飞拿着魔杖追着打月嫂回应掌掴婴儿是在赶虫子山西高速一大巴发生事故 已致13死高中生被打伤下体休学 邯郸通报李梦为奥运任务婉拒WNBA邀请19岁小伙救下5人后溺亡 多方发声王树国3次鞠躬告别西交大师生单亲妈妈陷入热恋 14岁儿子报警315晚会后胖东来又人满为患了倪萍分享减重40斤方法王楚钦登顶三项第一今日春分两大学生合买彩票中奖一人不认账张家界的山上“长”满了韩国人?周杰伦一审败诉网易房客欠租失踪 房东直发愁男子持台球杆殴打2名女店员被抓男子被猫抓伤后确诊“猫抓病”“重生之我在北大当嫡校长”槽头肉企业被曝光前生意红火男孩8年未见母亲被告知被遗忘恒大被罚41.75亿到底怎么缴网友洛杉矶偶遇贾玲杨倩无缘巴黎奥运张立群任西安交通大学校长黑马情侣提车了西双版纳热带植物园回应蜉蝣大爆发妈妈回应孩子在校撞护栏坠楼考生莫言也上北大硕士复试名单了韩国首次吊销离岗医生执照奥巴马现身唐宁街 黑色着装引猜测沈阳一轿车冲入人行道致3死2伤阿根廷将发行1万与2万面值的纸币外国人感慨凌晨的中国很安全男子被流浪猫绊倒 投喂者赔24万手机成瘾是影响睡眠质量重要因素春分“立蛋”成功率更高?胖东来员工每周单休无小长假“开封王婆”爆火:促成四五十对专家建议不必谈骨泥色变浙江一高校内汽车冲撞行人 多人受伤许家印被限制高消费

聚圣源 XML地图 TXT地图 虚拟主机 SEO 网站制作 网站优化