The HTML <iframe> tag is used to embed another HTML document or webpage within the current HTML document. It stands for "inline frame" and allows you to display content from another source within your web page.
Here's the basic structure of the <iframe> tag:
<iframe src="https://www.example.com"></iframe>
To embed a webpage, you specify the source URL using the src attribute. The content of the webpage will be loaded and displayed within the <iframe> element.
Example usage:
<iframe src="https://www.youtube.com/embed/VIDEO_ID"></iframe>
In this example, an iframe is used to embed a YouTube video by specifying the video's URL as the source. The YouTube video player will be displayed within the iframe.
The <iframe> tag has several attributes that allow you to customize its behavior and appearance. Some commonly used attributes include:
src: Specifies the source URL of the content to be displayed within the iframe.
width and height: Specifies the dimensions of the iframe in pixels or as a percentage of the parent container.
frameborder: Specifies whether or not to display a border around the iframe.
allowfullscreen: Specifies whether or not the content within the iframe can be displayed in fullscreen mode.
sandbox: Specifies a set of restrictions on the content within the iframe, such as restricting JavaScript execution.
Example with additional attributes:
<iframe src="https://www.example.com" width="500" height="300" frameborder="0" allowfullscreen></iframe>
In this example, the iframe has a specified width and height, no border (frameborder="0"), and allows the content to be displayed in fullscreen mode (allowfullscreen).
The <iframe> tag is commonly used when you want to embed external content such as maps, videos, social media feeds, or other web pages within your HTML document. It provides a way to integrate dynamic and interactive content from external sources seamlessly into your web page.