Video Embedding¶
Embed videos from various sources with responsive containers, privacy controls, and accessibility features.
Overview¶
Our video embedding features include:
- Responsive Containers - Videos adapt to any screen size
- Privacy-Enhanced Mode - YouTube no-cookie embedding
- Lazy Loading - Improved page performance
- Multiple Sources - YouTube, Vimeo, and HTML5 video
- Accessibility - Captions and transcripts support
- Dark Mode - Automatic theme adaptation
YouTube Videos¶
Basic Embedding¶
<div class="video-wrapper">
<iframe src="https://www.youtube-nocookie.com/embed/VIDEO_ID"
title="Video title"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen>
</iframe>
</div>
Privacy-Enhanced Embedding¶
Use youtube-nocookie.com
for GDPR compliance:
This video uses privacy-enhanced mode. YouTube won't store information about visitors unless they play the video.
With Custom Start Time¶
Start video at specific timestamp:
<div class="video-wrapper">
<iframe src="https://www.youtube-nocookie.com/embed/VIDEO_ID?start=120"
title="Video starting at 2:00"
allowfullscreen>
</iframe>
</div>
Vimeo Videos¶
Basic Vimeo Embed¶
<div class="video-wrapper">
<iframe src="https://player.vimeo.com/video/VIDEO_ID"
title="Video title"
frameborder="0"
allow="autoplay; fullscreen; picture-in-picture"
allowfullscreen>
</iframe>
</div>
Vimeo with Options¶
<div class="video-wrapper">
<iframe src="https://player.vimeo.com/video/VIDEO_ID?color=2196F3&title=0&byline=0&portrait=0"
allowfullscreen>
</iframe>
</div>
HTML5 Video¶
Basic HTML5 Video¶
<video controls>
<source src="path/to/video.mp4" type="video/mp4">
<source src="path/to/video.webm" type="video/webm">
Your browser does not support the video tag.
</video>
With Poster and Captions¶
<video controls poster="thumbnail.jpg">
<source src="video.mp4" type="video/mp4">
<track src="captions.vtt" kind="captions" srclang="en" label="English">
Your browser does not support the video tag.
</video>
Autoplay Background Video¶
Lazy Loading¶
With Placeholder Image¶
Improve performance by loading videos only when needed:
<div class="video-placeholder" onclick="loadVideo(this, 'VIDEO_ID')">
<img loading="lazy" src="https://img.youtube.com/vi/VIDEO_ID/maxresdefault.jpg" alt="Video thumbnail">
<div class="play-button">
<div class="play-icon"></div>
</div>
</div>
Aspect Ratios¶
16:9 (Default)¶
4:3 Classic¶
21:9 Ultra-wide¶
Square (1:1)¶
Video Gallery¶
Create a gallery of related videos:
Getting Started
Introduction to our documentation system
Advanced Features
Deep dive into advanced functionality
Accessibility¶
Video with Transcript¶
Video Transcript
This is where the full transcript of the video would go, making the content accessible to users who cannot watch the video or prefer to read.
Best Practices¶
- Always include title attribute on iframes for screen readers
- Provide captions for all videos
- Include transcripts for important content
- Use descriptive text around videos
- Test with keyboard navigation
Performance Tips¶
1. Use Lazy Loading¶
function loadVideo(element, videoId) {
const wrapper = document.createElement('div');
wrapper.className = 'video-wrapper';
wrapper.innerHTML = `<iframe src="https://www.youtube-nocookie.com/embed/${videoId}?autoplay=1" allowfullscreen></iframe>`;
element.replaceWith(wrapper);
}
2. Optimize Thumbnails¶
- Use WebP format when possible
- Compress images appropriately
- Use responsive image sizes
3. Limit Videos Per Page¶
- Consider pagination for video galleries
- Use placeholders for initial load
- Load videos on scroll
Social Media Integration¶
When videos are embedded, they automatically get optimized social media cards:
# Page metadata
---
title: Video Tutorial
description: Learn how to use our platform
image: https://img.youtube.com/vi/VIDEO_ID/maxresdefault.jpg
---
Privacy Considerations¶
GDPR Compliance¶
- Use
youtube-nocookie.com
domain - Add privacy notices where appropriate
- Consider lazy loading to avoid automatic tracking
- Provide alternative content methods
Cookie Notice¶
<div class="video-privacy-notice">
This video is embedded from YouTube.
By playing it, you accept YouTube's privacy policy.
</div>
Examples¶
Tutorial Video with Caption¶
MkDocs Tutorial: Getting started with documentation
Playlist Embedding¶
<div class="video-wrapper">
<iframe src="https://www.youtube-nocookie.com/embed/videoseries?list=PLAYLIST_ID"
title="Video playlist"
allowfullscreen>
</iframe>
</div>
Live Stream¶
<div class="video-wrapper">
<iframe src="https://www.youtube-nocookie.com/embed/live_stream?channel=CHANNEL_ID"
title="Live stream"
allowfullscreen>
</iframe>
</div>
Troubleshooting¶
Video Not Loading¶
- Check URL is correct
- Verify video privacy settings
- Test in different browsers
- Check console for errors
Responsive Issues¶
- Ensure parent container has width
- Check CSS conflicts
- Test on actual devices
- Verify aspect ratio class
Performance Problems¶
- Implement lazy loading
- Reduce number of embeds
- Use facade pattern
- Optimize page weight
Related Features¶
- Image Galleries - Display images with lightbox
- Diagrams - Embed interactive diagrams
- Code Blocks - Display code examples