Skip to content

Instantly share code, notes, and snippets.

@arraytools
Created December 7, 2025 00:03
Show Gist options
  • Select an option

  • Save arraytools/8778ffcd4727ea45fa216963becbdf09 to your computer and use it in GitHub Desktop.

Select an option

Save arraytools/8778ffcd4727ea45fa216963becbdf09 to your computer and use it in GitHub Desktop.
Embed youtube video to an HTML page. Default is 1080p. No autoplay.
<!DOCTYPE html>
<html>
<head>
<title>YouTube Video Embedder (1080p Size)</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
padding: 20px;
}
#url-input {
padding: 10px;
width: 80%;
max-width: 400px;
margin-bottom: 20px;
border: 1px solid #ccc;
border-radius: 5px;
}
#video-container {
margin: 20px auto;
width: 100%;
/* THIS IS THE CHANGE: Set max-width to 1920px (standard 1080p width).
The video player will scale up to this size.
*/
max-width: 1920px;
/* These properties maintain the perfect 16:9 aspect ratio */
position: relative;
padding-bottom: 56.25%; /* 9/16 = 0.5625 */
height: 0;
overflow: hidden;
}
#embedded-video {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border: none;
}
</style>
</head>
<body>
<h1>🎬 YouTube Video Embedder</h1>
<p>Paste a full YouTube video URL and press Enter:</p>
<input type="text" id="url-input" placeholder="Paste YouTube URL here..." onkeyup="handleInput(event)">
<div id="video-container">
<iframe id="embedded-video" src=""
allow="accelerometer; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
allowfullscreen>
</iframe>
</div>
<script>
function getYouTubeVideoId(url) {
var regExp = /^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/;
var match = url.match(regExp);
if (match && match[2].length === 11) {
return match[2];
} else {
return null;
}
}
function embedVideo(videoId) {
const iframe = document.getElementById('embedded-video');
if (videoId) {
// Video loads paused (no autoplay parameter)
const embedUrl = `https://www.youtube.com/embed/${videoId}`;
iframe.src = embedUrl;
} else {
iframe.src = "";
alert("Invalid YouTube URL. Please paste a full video link.");
}
}
function handleInput(event) {
if (event.keyCode === 13) {
const urlInput = document.getElementById('url-input').value;
const videoId = getYouTubeVideoId(urlInput);
embedVideo(videoId);
}
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment