iframe Tag
The iframe
tag is used to display another web page within a web page.
Example of iframe tag
<iframe src="https://example.com" width="500" height="300"></iframe>
Using this code, the example.com
web page will be displayed within a 500x300 pixels area on the current page.
Main Attributes of the iframe Tag
src
-
The
src
attribute specifies the URL of the web page to be embedded. -
Code example:
Example of iframe src attribute<iframe src="https://example.com"></iframe>
width
& height
-
The
width
andheight
attributes specify the size of theiframe
. -
Code example:
Example of iframe width & height attributes<iframe src="https://example.com" width="400" height="250"></iframe>
frameborder
-
The
frameborder
attribute determines whether the iframe has a border. However, modern web browsers no longer recommend using this attribute and suggest using theborder
property in CSS instead. -
Code example:
Example of iframe frameborder attribute<!-- Deprecated method -->
<iframe src="https://example.com" frameborder="0"></iframe>
<!-- Recommended method -->
<iframe src="https://example.com" style="border: none;"></iframe>
How to Use It?
The iframe
tag is mainly used to include videos (e.g., YouTube), maps (e.g., Google Maps), external websites, etc., within a web page.
Want to learn more?
Join CodeFriends Plus membership or enroll in a course to start your journey.