With the rise of short-form video content, YouTube Shorts has become a popular platform for engaging and entertaining audiences. If you’re looking to showcase these videos on your website, embedding YouTube Shorts can be a great way to increase user engagement. In this blog post, we’ll guide you through a simple method to embed YouTube Shorts into an HTML project. We’ll also explain each step so you can customize the code as needed.
Embedding YouTube Shorts on your website offers several benefits:
Here’s the basic HTML code for embedding YouTube Shorts:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>YouTube Shorts Embed</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin: 0;
padding: 0;
background-color: #f4f4f4;
}
.container {
padding: 20px;
}
iframe {
border: none;
width: 100%;
max-width: 400px;
height: 720px;
}
.description {
margin-top: 20px;
font-size: 18px;
color: #555;
}
</style>
</head>
<body>
<div class="container">
<h1>Watch YouTube Shorts</h1>
<!-- Embed YouTube Shorts -->
<iframe
src="https://www.youtube.com/embed/<SHORTS_VIDEO_ID>"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen>
</iframe>
<div class="description">
<p>Enjoy trending YouTube Shorts directly on your website!</p>
</div>
</div>
</body>
</html>
<SHORTS_VIDEO_ID>Every YouTube Shorts video has a unique identifier in its URL. For instance:
https://youtube.com/shorts/abc123abc123Replace <SHORTS_VIDEO_ID> in the code with the actual video ID to display the desired Shorts video.
The included CSS ensures the iframe is responsive, adjusting its size based on the screen width. The max-width property limits the video’s width to 400px, which is ideal for mobile and desktop views.
Want to showcase multiple Shorts videos? Use a playlist embed:
<iframe
src="https://www.youtube.com/embed?list=<PLAYLIST_ID>"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen>
</iframe>
Replace <PLAYLIST_ID> with your YouTube playlist’s unique ID.
If you want users to search for Shorts or dynamically load videos, you can enhance the functionality with JavaScript. For example:
function loadShorts(videoId) {
const iframe = document.querySelector('iframe');
iframe.src = `https://www.youtube.com/embed/${videoId}`;
}
// Example Usage
loadShorts('abc123');
Embedding YouTube Shorts on your website is a simple yet effective way to enhance your content and engage visitors. With the provided HTML template and customization tips, you’re well-equipped to integrate Shorts seamlessly into your web project. Whether you’re a beginner or an experienced developer, this guide offers a solid foundation to get started.
Have any questions or need help with additional features? Let us know in the comments below!