HTML iframe Tag
The <iframe>
tag allows you to display another webpage within your current webpage.
The embedded webpage will occupy a defined area within a frame on your webpage.
For instance, the following HTML code can be used to embed another webpage into your current webpage.
<iframe src="https://www.example.com"></iframe>
In the code above, the src
attribute specifies the URL of the webpage you want to embed.
This example shows how to display the "https://www.example.com" webpage inside an <iframe>
tag.
To display a YouTube video uploaded to your webpage, you need to know the URL of the YouTube video file.
However, it is impractical to directly include the video file due to its large size, and YouTube doesn't share direct access to video files as a means of copyright protection.
Nonetheless, many web pages still show YouTube videos, right?
YouTube provides an <iframe>
tag to allow videos to be shared easily without the need for large file sizes while still protecting the rights of content creators.
<iframe width="320" height="180" src="https://www.youtube.com/embed/W0DCi5kwURM" title="iframe example" allow="fullscreen;" ></iframe>
The above iframe displays a YouTube video on your website with a width of 320px and a height of 180px.
Here, "src" can be found by right-clicking on the YouTube video, selecting the Copy embed code
, and then pasting the value into a text input.
Alternatively, conform to the format https://www.youtube.com/embed/{YouTubeVideoID}
and replace {YouTubeVideoID}
with the actual video ID.
For example, the unique ID of the YouTube video with the address https://www.youtube.com/watch?v=AY5qcIq5u2g is AY5qcIq5u2g
.
You would insert "https://www.youtube.com/embed/AY5qcIq5u2g"
in the src, right?
Additionally, title="iframe example"
sets the title of the iframe element, and allow="fullscreen;"
enables the fullscreen button on the YouTube iframe.
This way, even without knowing the original address of the YouTube video file, you can display the uploaded video on your webpage using an iframe.
Now, let's place a YouTube video in the fourth grid item of the gallery!
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help