To embed a YouTube video in an HTML webpage, you can use the <iframe> element.
The src attribute should be set to the URL of the video on YouTube, and the width and height attributes can be set to specify the size of the video player.
<iframe width="560" height="315"
src="https://www.youtube.com/embed/
VIDEO_ID"
frameborder="0" allow="accelerometer;
autoplay;
clipboard-write; encrypted-media;
gyroscope; picture-in-picture"
allowfullscreen></iframe>
You can change the "VIDEO_ID" in the src to the id of the video you want to embed.
Additionally, you can also add some extra attributes like title and frameborder to configure the video player.
<iframe width="560" height="315"
src="https://www.youtube.com/embed/
VIDEO_ID"
frameborder="0" title="Video Title"
allowfullscreen></iframe>
You can also use the youtube video link and wrap it into the iframe tag for embedding the video.
<iframe width="560" height="315"
src="https://www.youtube.com/watch?
v=VIDEO_ID"
frameborder="0" allowfullscreen>
</iframe>
There are several attributes that can be used with the <iframe> element to customize the appearance and behavior of the embedded video. Some commonly used attributes include:
src: The URL of the video to be embedded. This is required for the video to be displayed.
width and height: The width and height of the video player, in pixels.
frameborder: The width of the border around the video player, in pixels. A value of "0" will remove the border.
allowfullscreen: Allows the video to be played in fullscreen mode.
title: Title of the video
id: unique id for the iframe
class: class name for the iframe
sandbox : Enables an extra set of restrictions for the content in the iframe.
seamless : Indicates that the iframe should be displayed as if it is a part of the containing document, rather than being isolated in a separate browsing context.
srcdoc : The HTML content of the page to show in the iframe.
name : The name of the iframe.
Please note that some of these attributes might not be supported in some older browsers.
No comments:
Post a Comment