# Video ## Formats - Offer more than one source and let the browser pick: WebM with AV1 video and Opus audio first for the best compression, then MP4 with AVC (H.264) video and AAC audio as the broadly supported fallback. Check licensing for proprietary codecs, and check that the target clients decode AV1 before relying on it alone. ```html ``` - Replace animated GIFs with a short muted, looping video (`autoplay muted loop playsinline`); it is usually far smaller. - For long or large videos, use adaptive streaming (HLS or DASH) through the project's existing player or video service instead of serving one large file. ## Playback and loading - Autoplay only muted video or video without an audio track; browsers block autoplay with sound until the user interacts. Add `playsinline` for inline autoplay on iOS Safari. Never autoplay audio. - Keep `controls` unless the design provides its own accessible controls, and give users a way to pause any moving content. - Set `preload="none"` or `metadata` for videos the user may not play, and add `loading="lazy"` for offscreen videos where supported. - Give every video a poster and intrinsic `width` and `height` to reserve space. When a video is the largest contentful element, preload its poster with high fetch priority and do not lazy-load it. ## Accessibility - Provide captions (WebVTT ``) for prerecorded video with speech or meaningful sound (WCAG 1.2.2, level A). - When the picture carries information the audio does not, provide audio description or a full text alternative (WCAG 1.2.3 level A; 1.2.5 level AA requires audio description). - Live video with audio needs live captions (WCAG 1.2.4, level AA). - Video-only content needs a text or audio alternative (WCAG 1.2.1, level A). ## Desktop and mobile apps - In WPF, play media with `MediaElement`; in .NET MAUI, use `MediaElement` from `CommunityToolkit.Maui.MediaElement`, initialized with `UseMauiCommunityToolkitMediaElement` (enable the Android foreground service only when background playback or media notifications are required). References: [MDN video codecs](https://developer.mozilla.org/en-US/docs/Web/Media/Guides/Formats/Video_codecs), [MDN autoplay](https://developer.mozilla.org/en-US/docs/Web/Media/Guides/Autoplay), [web.dev lazy-loading video](https://web.dev/articles/lazy-loading-video), [WCAG 2.2](https://www.w3.org/TR/WCAG22/).