HTML Iframe
An HTML iframe (short for inline frame) is used to insert a new HTML document into the current HTML document. This allows you to display content from another site or another part of the same site in your site.
Here are some common HTML iframes
External Inputs
You can embed content from other websites such as maps, videos, or social media feeds into your site using iframes.
Advertisements being shown
Ads from the ad network can be displayed in iframes on web pages.
Third Party Integration
Iframes can be used to integrate third-party applications or widgets into the web, such as calendars, chat widgets, or booking systems.
Modular system design
Iframes allow you to divide your web page into modular components, each with distinct content or functionality.
Proper input
Iframes provide some protection by sandboxing embedded content, isolating it from the rest of the web page and preventing malicious code from affecting the main page
However, it is important to use iframes judiciously, as overusing them can affect page performance and user experience, and inserting external content if not done properly a, it can pose a safety hazard
Basic Syntax-
Example-
Here is a basic example of how you can show a YouTube video on an HTML page
In the above example-
The “iframe” element is used to embed a YouTube video. The src attribute specifies the URL of the video to be embedded (in this case "https://www.youtube.com/embed/N8H1y7DkVPo"). The width
and height
attributes determine the shape of the iframe
, with frameborder="0"
removing the border around the iframe. The allowfullscreen
attribute enables video playback in full screen mode.
Output-
Also, Read: Explain the HTML Events.
Leave Comment