Youtube Html5 Video Player Codepen Apr 2026

// Volume volumeSlider.addEventListener('input', () => video.volume = volumeSlider.value; muteBtn.textContent = video.volume === 0 ? '🔇' : '🔊'; );

const video = document.getElementById('myVideo'); const playPauseBtn = document.getElementById('playPauseBtn'); const progressContainer = document.querySelector('.progress-container'); const progressBar = document.getElementById('progressBar'); const timeDisplay = document.getElementById('timeDisplay'); const volumeSlider = document.getElementById('volumeSlider'); const muteBtn = document.getElementById('muteBtn'); const speedSelect = document.getElementById('speedSelect'); const fullscreenBtn = document.getElementById('fullscreenBtn'); // Play/Pause function togglePlay() if (video.paused) video.play(); playPauseBtn.textContent = '⏸'; else video.pause(); playPauseBtn.textContent = '▶';

.player-container max-width: 900px; width: 90%; background: #000; border-radius: 20px; overflow: hidden; box-shadow: 0 20px 35px rgba(0,0,0,0.5);

.controls display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 12px 18px; background: #1e1e1e; color: white; youtube html5 video player codepen

button:hover background: #555;

.progress-container flex: 1; background: #444; height: 6px; border-radius: 5px; cursor: pointer; position: relative;

button, select background: #333; border: none; color: white; padding: 6px 12px; border-radius: 30px; cursor: pointer; font-size: 1rem; transition: 0.2s; // Volume volumeSlider

// Update progress bar & time video.addEventListener('timeupdate', () => const percent = (video.currentTime / video.duration) * 100; progressBar.style.width = $percent% ;

playPauseBtn.addEventListener('click', togglePlay); video.addEventListener('click', togglePlay);

// Playback speed speedSelect.addEventListener('change', () => video.playbackRate = parseFloat(speedSelect.value); ); 💡 Pro tip : Replace the sample video with your own

);

body background: #0a0a0a; display: flex; justify-content: center; align-items: center; min-height: 100vh; font-family: system-ui, 'Segoe UI', sans-serif;

#timeDisplay font-size: 0.85rem; font-family: monospace;

: Copy the code blocks above into CodePen and start tweaking. You’ll be surprised how professional a few lines of HTML/CSS/JS can look. 💡 Pro tip : Replace the sample video with your own .mp4 hosted on GitHub Pages or any public CDN. Liked this tutorial? Tap the ❤️ on the CodePen and share your custom version in the comments.