ReferenceButtons
media-play-button
Accessible play/pause button with keyboard support and customizable rendering
Import
Anatomy
Behavior
The play button is a three-state button: play, pause, and replay. When media reaches the end (ended state), clicking restarts playback from the beginning.
While media with autoplay is trying to start, the button shows pause, and clicking it cancels the autoplay. If the browser refuses the autoplay, the button returns to play.
Styling
Style with the [data-paused] and [data-ended] attributes to show/hide play/pause/replay icons based on state. While autoplay is pending, the button omits data-paused and adds data-started, so the pause icon shows. For example:
The data-started attribute is present while the media tries to autoplay, and from first play until a new source is loaded. Use this to hide the play button when media hasn’t started yet:
Accessibility
Renders a <button> element with an automatic aria-label that updates based on state: “Play”, “Pause”, or “Replay”. Override with the label prop, which accepts a text descriptor, literal string, or function returning either. A text descriptor contains an opaque translation key and English fallback, for example { key: 'buttons.play', text: 'Play video' }. Keyboard activation: Enter / Space.