Table of contents
Introduction
<iframe>
tag:Stands for "inline frame."
It allows you to embed content from another web page or external source within your own web page.
Typically used for embedding videos, maps, social media widgets, advertisements, or any other external content.
The content displayed within the
<iframe>
is loaded from a different URL, and the browser treats it as a separate document within the main document.The
<iframe>
tag requires asrc
attribute to specify the source URL of the content you want to embed.
<iframe src="https://www.youtube.com/embed/VIDEO_ID"></iframe>
Iframe Attributes
The <iframe>
tag in HTML supports several attributes that allow you to customize and control the behavior of the embedded content. Here are some commonly used attributes:
src
: Specifies the URL of the content to be embedded within the iframe. Example:<iframe src="
https://www.example.com"></iframe>
width
andheight
: Sets the width and height dimensions of the iframe. Example:<iframe src="..." width="500" height="300"></iframe>
frameborder
: Indicates whether to display a border around the iframe. Example:<iframe src="..." frameborder="0"></iframe>
allowfullscreen
: Allows the content within the iframe to be displayed in fullscreen mode. Example:<iframe src="..." allowfullscreen></iframe>
sandbox
: Enables a restricted sandbox environment for the iframe, restricting certain capabilities like scripts, form submission, and more. Example:<iframe src="..." sandbox="allow-scripts"></iframe>
scrolling
: Specifies whether to display scrollbars within the iframe when the content exceeds the iframe's dimensions. Example:<iframe src="..." scrolling="no"></iframe>
name
: Assigns a name to the iframe, which can be used as the target for form submissions or as thetarget
attribute value for anchor links. Example:<iframe src="..." name="myFrame"></iframe>
allow
: Specifies a list of permissions for the content within the iframe, such as allowing autoplay, geolocation access, microphone usage, and more. Example:<iframe src="..." allow="autoplay; geolocation"></iframe>