video

The video element embeds video content with native playback controls, responsive sizing, and aspect ratio variants for different video formats.

Description

The <video> element embeds video content with native browser playback controls. Vanilla Breeze styles videos to be responsive by default with a dark background, and provides aspect ratio variants for common video formats.

Videos support multiple <source> elements for format fallbacks and <track> elements for captions and subtitles.

When to Use

  • Self-hosted video - Videos hosted on your own server
  • Background video - Decorative looping video without controls
  • Video galleries - Collections of video content
  • Instructional content - Tutorials and how-to videos

When to Use iframe Instead

  • YouTube, Vimeo, or other video hosting services - use <iframe> embeds
  • Videos requiring DRM or advanced features provided by third-party players

Variants and Aspect Ratios

Vanilla Breeze provides variant classes for video styling (.rounded, .full) and aspect ratio classes (.widescreen, .standard, .square, .ultrawide) for consistent video dimensions.

Variant Classes

Aspect Ratio Classes

Class Aspect Ratio Use Case
.widescreen 16:9 Standard HD video, YouTube, most modern content
.standard 4:3 Classic TV, older content, some presentations
.square 1:1 Social media (Instagram), thumbnails
.ultrawide 21:9 Cinematic content, ultrawide monitors

Background Video

Decorative looping video without controls. Combine autoplay, muted, loop, and playsinline for seamless background playback.

Chapter Markers

Add data-chapter-list to a <track kind="chapters"> element to render a clickable chapter list below the video. The current chapter highlights during playback, and clicking a chapter seeks to that timestamp.

Without JavaScript, the video plays normally with chapters available in the browser's native UI where supported.

WebVTT Chapter Format

Chapters use standard WebVTT format. Each cue defines a time range and chapter title:

Video Attributes

Attribute Description
controls Show native playback controls (play, pause, volume, fullscreen)
poster Image shown before video loads or plays
autoplay Start playing automatically (requires muted in most browsers)
muted Start with audio muted
loop Restart video when it ends
playsinline Play inline on mobile instead of fullscreen
preload none, metadata, or auto

Motion Preferences

Vanilla Breeze respects prefers-reduced-motion for autoplay videos. When a user has indicated they prefer reduced motion, autoplay videos are paused automatically. This ensures background and decorative videos don't cause discomfort for motion-sensitive users.

Fallback Content

Provide fallback text or links for browsers that don't support video or the specified formats.

Accessibility

Captions and Subtitles

Use <track> elements to provide captions for deaf and hard-of-hearing users.

Best Practices

  • Always provide captions for videos with speech
  • Use poster to show a meaningful preview image
  • Don't autoplay videos with sound - use muted for autoplay
  • Provide a text transcript for important video content
  • Ensure controls are keyboard accessible (native controls are)
  • Consider users who disable autoplay or animations

Related

  • <audio> - Audio-only content, similar API
  • <source> - Define multiple video sources for format fallback
  • <track> - Captions, subtitles, and other timed text
  • <figure> - Wrap videos that need captions
  • <iframe> - Embed third-party video players
  • <video-player> - Enhanced video playback with overlay controls, captions, fullscreen, and playlist support
  • <audio-player> - Enhanced audio playback with progress, seeking, and playlist support
  • <audio-visualizer> - Real-time audio frequency visualization

CSS Reference

Styles defined in /src/native-elements/video/styles.css

Selector Properties
video max-inline-size: 100%; block-size: auto; display: block; background: var(--color-gray-900);
video.full inline-size: 100%;
video.widescreen aspect-ratio: 16 / 9; object-fit: cover;
video.standard aspect-ratio: 4 / 3; object-fit: cover;
video.square aspect-ratio: 1; object-fit: cover;
video.ultrawide aspect-ratio: 21 / 9; object-fit: cover;
video.rounded border-radius: var(--radius-m); overflow: hidden;
.chapter-list Chapter list nav container rendered by data-chapter-list enhancer
.chapter-list li[data-active] Highlights the currently playing chapter