Video Player
Responsive video playback with accessible custom controls.
VideoPlayer is a responsive video component with a custom control bar. It renders a native video element and adds consistent play, seek, volume, captions, playback speed and fullscreen controls.
See the live Video Player showcase.
Basic usage
<VideoPlayer
src="/media/intro.mp4"
poster="/media/intro-poster.jpg"
title="Product introduction"
/>The player fills its container by default and uses a 16 / 9 aspect ratio. Set width, height or style for a fixed or custom size. aspectRatio can be a number or any valid CSS ratio string.
Sources and responsive sizing
Use sources when the browser should choose between different formats. src is convenient for a single source.
<VideoPlayer
sources={[
{ src: '/media/intro.webm', type: 'video/webm' },
{ src: '/media/intro.mp4', type: 'video/mp4' },
]}
width="100%"
aspectRatio="21 / 9"
/>fit controls how the video fills its box: contain preserves the whole frame, cover fills the box and may crop, and fill stretches the frame.
Playback controls
The custom control bar includes play/pause, a seekable progress bar, current time and duration, volume, mute, playback speed and fullscreen. Each control can be hidden independently. controls={false} hides the control bar and the center play button.
The center action follows the pointer state: a paused video keeps its play action available, while the pause action for a playing video is hidden when the pointer leaves the player. Moving the pointer back over the player reveals the pause action again.
<VideoPlayer
src="/media/demo.mp4"
showVolumeControl={false}
showPlaybackRateControl={false}
showFullscreenControl={false}
rates={[0.75, 1, 1.25, 1.5]}
/>Supported keyboard shortcuts while the player is focused:
SpaceorK— play/pause;ArrowLeftandArrowRight— seek five seconds backward/forward;M— mute/unmute;F— enter/exit fullscreen.
Autoplay and playback state
autoPlay, loop, muted, playsInline and preload map to the native video behavior. Browsers commonly block autoplay with sound, so autoplay examples should normally also set muted.
<VideoPlayer src="/media/background.mp4" autoPlay muted loop playsInline preload="auto" />Use defaultVolume and defaultPlaybackRate to set the initial state. onPlay, onPause, onEnded and onTimeUpdate provide lifecycle callbacks.
Captions
Pass a track to provide captions or subtitles. The captions button appears automatically when a track exists. Set track.default to show them initially.
<VideoPlayer
src="/media/demo.mp4"
track={{
src: '/media/demo.en.vtt',
kind: 'subtitles',
srcLang: 'en',
label: 'English',
default: true,
}}
/>Loading and fallback
poster is shown before playback. fallback is rendered when no source exists or the video fails to load. onError is called in addition to the internal error state.
The video itself and the center action both toggle playback. The center action shows Play for a paused video. While the video is playing, the center Pause action is available on hover and is hidden when the pointer leaves the player. The bottom control bar remains independently configurable through controls and the individual show*Control props.
API Reference
| Prop | Values | Default | Description |
|---|---|---|---|
src | string | — | Single video source. |
sources | VideoSource[] | — | Ordered sources with optional MIME types. |
poster | string | — | Preview image before playback. |
title | string | — | Native video title for assistive technology. |
aria-label | string | Video player | Accessible label for the player region. |
aspectRatio | number | string | 16 / 9 | Player ratio. |
width | number | string | 100% | Player width. |
height | number | string | — | Player height. |
fit | contain | cover | fill | contain | Video fitting mode. |
size | sm | default | lg | default | Control density. |
controls | boolean | true | Shows the custom control bar and center play button. |
autoHideControls | boolean | false | Hides controls while the pointer is away. |
autoPlay | boolean | false | Starts playback when allowed by the browser. |
loop | boolean | false | Restarts after the video ends. |
muted | boolean | false | Starts without sound. |
defaultVolume | number | 1 | Initial volume from 0 to 1. |
defaultPlaybackRate | number | 1 | Initial playback speed. |
rates | number[] | [0.5, 1, 1.25, 1.5, 2] | Options in the speed menu. |
playsInline | boolean | true | Keeps playback inline on mobile browsers. |
preload | none | metadata | auto | metadata | Native preload hint. |
track | VideoTrack | — | Caption or subtitle track. |
showVolumeControl | boolean | true | Shows volume and mute controls. |
showPlaybackRateControl | boolean | true | Shows the playback speed menu. |
showFullscreenControl | boolean | true | Shows fullscreen control. |
showCaptionsControl | boolean | true | Shows captions control when track exists. |
onPlay | () => void | — | Called when playback starts. |
onPause | () => void | — | Called when playback pauses. |
onEnded | () => void | — | Called when playback finishes. |
onTimeUpdate | (currentTime, duration) => void | — | Called during playback and seeking. |
onError | video error handler | — | Called when the source fails. |
fallback | ReactNode | Video is unavailable | Content shown when no video can be played. |
className | string | — | Additional class for the player wrapper. |
videoClassName | string | — | Additional class for the native video element. |
style | CSSProperties | — | Inline styles for the wrapper. |
VideoSource
| Field | Type | Description |
|---|---|---|
src | string | Video URL. |
type | string | Optional MIME type such as video/mp4. |
VideoTrack
| Field | Type | Description |
|---|---|---|
src | string | WebVTT track URL. |
kind | subtitles | captions | descriptions | chapters | metadata | captions |
srcLang | string | Language code. |
label | string | Human-readable language label. |
default | boolean | Shows the track initially. |
Accessibility
The player is a focusable region with labelled buttons, labelled range controls, keyboard shortcuts and a native video element. Always provide a meaningful title and poster where appropriate, and provide captions for spoken content.