How to embed youtube video in HTML using iframe?

In this post, You’ll learn how to embed a YouTube video into a webpage. To embed a YouTube video in HTML, simply follow the steps listed below.

1. Go to YouTube and open the video you wish to embed.

2. A share button is located just below the video (see the screenshot below). Click on “Share”.

3. Following the share button’s click. A small window will appear (see the screenshot below). There is now an embed option there. Choose “embed” from the menu.

4. When you click the embed button, the iframe code is displayed for you to copy and paste into your HTML file. Just click on “copy” to copy the code and paste it into your HTML file.

Now let’s see an example HTML file. I will paste this code into an HTML file that I created.

<!DOCTYPE html>
<html>
    <head>
        <title>Embedded YouTube video</title>
        <style>
            iframe{
                margin-left: 28% 
            }
        </style>
    </head>
    <body>
        <iframe width="560" height="315" src="https://www.youtube.com/embed/jiAj188ZJBY" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
    </body>
</html>

Output :

If you want to know about the iframe then here’s the link – https://developerxon.com/2022/07/13/what-is-an-iframe-in-html-html-inline-frame/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: