Video content has become popular, making embedding videos on your web essential. You can embed a YouTube video on your blog post, web page, or landing page to engage your audience.
Because HTML describes the structure of a webpage, knowing how to embed a video in HTML is essential. But how do you embed a YouTube video in HTML?
You can embed a YouTube video in HTML in two ways. The first option is to embed the video using the iframe tag. With this method, you click the “Share” button and choose the “Embed” feature. Next, copy and paste the embed link on your HTML file. The second option entails embedding the YouTube video using the object tag using the data attribute.
This tutorial shows you how to embed a YouTube video in HTML.
An Overview of Embedding a YouTube Video in HTML
Embedding a YouTube video on your webpage adds value to its content. For instance, if you embed a how-to-tutorial video on a post about the same subject, you give the reader options. They can choose to read the blog post or watch the video instead.
The same goes for landing pages. An introductory video adds value to your landing page. Instead of telling the visitor what your site offers, show them a video.
Embedding a YouTube video in HTML is not easy, but with a little guidance, you will ace it.
How To Embed a YouTube Video in HTML
You can embed a YouTube video in an HTML file in two ways: using the iframe tag and the object tag. Below are the two ways of embedding a YouTube video in HTML.
Method #1: Embedding a YouTube Video in HTML Using the Iframe Tag
Follow the steps below to embed a YouTube video in HTML using the iframe tag.
- Navigate to YouTube and log in to your account.
- Search for the video you want to embed.
- Choose the video from the search results and play it.
- Open the HTML file you want to embed the YouTube video.
- Type the HTML code on the file.
- Place your cursor on the section you want to embed the video.
- Define the <iframe> tag.
- Input the src attribute within the <iframe> tag.
- Return to YouTube and copy the video URL.
- Paste the URL in the src attribute section.
- Set the embedded video’s dimensions and add them in the <iframe> tag.
- Run the code.
You have successfully embedded a YouTube video in HTML using the iframe tag. Alternatively, you can use this shortcut to embed the video on your HTML document.
- Play the video you want to embed in HTML.
- Click “Share.”
- Select “Embed” in the sharing options.
- Copy the code.
- Open the HTML file you want to embed the video.
- Paste the code in the HTML file.
- Run the code.
Method #2: Embedding a YouTube Video in HTML Using the Object Tag
An object tag embeds multimedia files in HTML, including videos, images, and PDFs. Here is the step-by-step guide to embed a YouTube video in HTML using the object tag.
- Navigate to YouTube and search for the video you want to embed on the HTML file.
- Play the video.
- Open the HTML file you want to embed the video.
- Type the HTML code on the file.
- Define the <object> tag.
- Input the data attribute within the <object> tag.
- Return to YouTube and copy the video URL.
- Paste the URL in the data attribute section.
- Set the video’s height and width and add the dimensions within the <object>tag.
- Run the code.
The YouTube video will be embedded in your HTML file.
Winding Up
Embedding a YouTube video on an HTML file comes in handy in various situations. You can embed a video on a blog post, a service page, a landing page, and more.
There are two ways to embed a YouTube video in HTML, including using the <iframe> and the <object> tag. We have detailed the step-by-step process for both ways in this guide.
FAQs
Yes, you can embed a YouTube video in an HTML file, either using the <iframe> or <object> tags.
Yes, it’s legal to embed YouTube videos on a website. As a content manager, you can embed multiple multimedia on your webpage, including videos and applications.
To embed a YouTube video in HTML without IFrame, use the <object> tag and specify the video details using the data attribute.