Preparation
🌐 ⏐ HTML5 Questions
8. IFrames

IFrames in HTML

An iframe, or inline frame, is an HTML element used to embed another HTML document within the current document. IFrames are commonly used to display content from another source, such as a video player, map, or social media widget, seamlessly within a webpage.

Syntax:

<iframe src="URL" width="width" height="height" frameborder="0" allowfullscreen></iframe>

Attributes:

  • src: Specifies the URL of the document to be embedded.
  • width: Sets the width of the iframe.
  • height: Sets the height of the iframe.
  • frameborder: Controls whether a border should be displayed around the iframe. Typically set to "0" to remove borders.
  • allowfullscreen: Allows the content within the iframe to be displayed in fullscreen mode.

Example:

<iframe src="https://www.youtube.com/embed/dQw4w9WgXcQ" width="560" height="315" frameborder="0" allowfullscreen></iframe>

Explanation:

  • In this example, an iframe is used to embed a YouTube video.
  • The src attribute specifies the URL of the video.
  • The width and height attributes define the dimensions of the iframe to properly display the video.
  • The frameborder attribute is set to "0" to remove any border around the iframe.
  • The allowfullscreen attribute allows the video to be played in fullscreen mode.

IFrames provide a convenient way to integrate external content into a webpage while maintaining its structure and layout. However, they should be used judiciously, considering factors like security and performance implications.