How to Put Two YouTube Videos Side by Side in HTML?

If you want to show two YouTube videos next to each other on your website, this guide will show you how to put two YouTube videos side by side in HTML.

This is useful if you want to compare videos or just show them together in a clean way.

How to Put Two YouTube Videos Side by Side in HTML?

1. Basic HTML Structure

Before we start, make sure you have a basic understanding of HTML. Here’s a simple structure to get you started:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Two YouTube Videos Side by Side</title>
</head>
<body>
    <!-- Your content will go here -->
</body>
</html>

This is the basic structure of an HTML document. Inside the <body> tag, we’ll add the code to place two YouTube videos side by side.

2. Embed YouTube Videos

First, you need the embed code for the two YouTube videos.

You can get this from YouTube by clicking the “Share” button below the video, then choosing “Embed”.

Copy the embed code, which will look something like this:

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

You’ll need to replace VIDEO_ID with the actual ID of the video you want to embed.

Also Read: How Much Traffic Can a Small Google Server Handle?

3. Use HTML and CSS for Side-by-Side Layout

To put two YouTube videos side by side in HTML, you can use a combination of HTML and CSS.

Here’s a simple method:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Two YouTube Videos Side by Side</title>
    <style>
        .video-container {
            display: flex;
            justify-content: space-between;
        }
        .video-container iframe {
            width: 49%; /* Adjust the width as needed */
        }
    </style>
</head>
<body>
    <div class="video-container">
        <iframe src="https://www.youtube.com/embed/VIDEO_ID_1" frameborder="0" allowfullscreen></iframe>
        <iframe src="https://www.youtube.com/embed/VIDEO_ID_2" frameborder="0" allowfullscreen></iframe>
    </div>
</body>
</html>

In this code:

  • .video-container is a div that contains both YouTube videos.
  • The display: flex; style makes the videos appear side by side.
  • The justify-content: space-between; style adds space between the videos.
  • The width: 49%; style sets the width of each video to 49% of the container’s width.
    This allows for a small gap between them.

4. Adjusting the Layout

If you want more control over how the videos appear, you can adjust the width and justify-content properties:

  • To reduce the space between the videos, you can increase the width of each video to, for example, 50%.
  • To add more space between the videos, you can reduce the width or use margin properties.

Here’s an example with a bit more space between the videos:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Two YouTube Videos Side by Side</title>
    <style>
        .video-container {
            display: flex;
            justify-content: space-around;
        }
        .video-container iframe {
            width: 48%; /* Adjusted width for more space */
        }
    </style>
</head>
<body>
    <div class="video-container">
        <iframe src="https://www.youtube.com/embed/VIDEO_ID_1" frameborder="0" allowfullscreen></iframe>
        <iframe src="https://www.youtube.com/embed/VIDEO_ID_2" frameborder="0" allowfullscreen></iframe>
    </div>
</body>
</html>

5. Responsive Design

To make sure your videos look good on all screen sizes, you can use responsive design techniques.

How to Put Two YouTube Videos Side by Side in HTML?

One simple way is to use the max-width property in your CSS:

<style>
    .video-container {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
    }
    .video-container iframe {
        width: 100%;
        max-width: 49%; /* Responsive width */
        margin-bottom: 10px;
    }
</style>

With this code:

  • The flex-wrap: wrap; style allows the videos to stack on top of each other if the screen is too narrow.
  • The max-width: 49%; style ensures the videos take up less than half the width of the container, allowing them to fit side by side on wider screens.

6. Conclusion

Now you know how to put two YouTube videos side by side in HTML.

This method is simple and uses basic HTML and CSS, making it easy to adjust to your needs.

Whether you’re creating a tutorial, comparing videos, or just want to display two videos together, this guide gives you a clear path to do it.

By following these steps, you’ll be able to place YouTube videos side by side on your website, creating a better visual experience for your visitors.

6 thoughts on “How to Put Two YouTube Videos Side by Side in HTML?”

  1. Your blog is a treasure trove of valuable insights and thought-provoking commentary. Your dedication to your craft is evident in every word you write. Keep up the fantastic work!

  2. I’m often to blogging and i really appreciate your content. The article has actually peaks my interest. I’m going to bookmark your web site and maintain checking for brand spanking new information.

  3. naturally like your web site however you need to take a look at the spelling on several of your posts. A number of them are rife with spelling problems and I find it very bothersome to tell the truth on the other hand I will surely come again again.

  4. I was recommended this website by my cousin I am not sure whether this post is written by him as nobody else know such detailed about my trouble You are amazing Thanks

Leave a comment

profile-pic

Jaypalsinh Jadeja

Jaypalsinh is a young web developer and digital marketing expert, since 2020. He has worked in more than 7 Blogs and Websites and have 4+ years of experience in Search Engine Optimization.