An HTML iframe, short for inline frame, is a powerful feature that allows developers to embed another HTML document within the current web page. It is commonly used for embedding videos, maps, and other external content from a different source.
Iframe Example:
An <iframe>
element creates an inline frame that can load and display content from a different source or domain within the current web page. This makes it a versatile tool for embedding videos, forms, or interactive widgets.
<iframe src="url" width="width-value" height="height-value"></iframe>
The src
attribute specifies the URL of the document to display within the iframe. Width and height attributes define the dimensions of the iframe.
src
: Specifies the URL of the content to embed.width
: Defines the width of the iframe (in pixels or percentages).height
: Defines the height of the iframe (in pixels or percentages).title
: Provides a brief description of the iframe's content for accessibility.allow
: Enables permissions for certain features (e.g., fullscreen
, camera
).loading
: Optimizes performance by using lazy
or eager
loading for the iframe.sandbox
: Restricts iframe capabilities for enhanced security.allowfullscreen
: Allows the iframe content to be viewed in fullscreen mode.
<iframe width="560" height="315"
src="https://www.youtube.com/embed/dQw4w9WgXcQ"
title="YouTube video player"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen></iframe>
<iframe
src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3153.8354345096743!2d-122.41941558468204!3d37.77492927975933!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x80858064f6dfd555%3A0x80858064f6dfd555!2sSan%20Francisco%2C%20CA%2C%20USA!5e0!3m2!1sen!2sin!4v1625471467358!5m2!1sen!2sin"
width="600"
height="450"
style="border:0;"
allowfullscreen=""
loading="lazy"></iframe>
<iframe src="about.html"
width="800"
height="600"
title="About Us Page">
</iframe>
sandbox
attribute to enhance security.loading="lazy"
attribute for non-critical iframes.<iframe>
tag specifies an inline framesrc
attribute defines the URL of the page to embedtitle
attribute (for screen readers)height
and width
attributes specify the size of the iframeborder:none;
to remove the border around the iframe<iframe>
Elementsrc
attribute with the URL of the content.width
and height
for the iframe's dimensions.sandbox
, loading
, or allowfullscreen
as needed.sandbox
attribute can help mitigate these risks.