Skip to content
FrameworkStyle

VolumeSlider

A slider component for controlling media playback volume

Import

import { VolumeSlider } from '@videojs/react';

Anatomy

<VolumeSlider.Root>
  <VolumeSlider.Track>
    <VolumeSlider.Fill />
  </VolumeSlider.Track>
  <VolumeSlider.Thumb />
  <VolumeSlider.Preview>
    <VolumeSlider.Value type="pointer" />
  </VolumeSlider.Preview>
</VolumeSlider.Root>

Behavior

Controls the media volume level. The slider maps its 0–100 internal range to the media’s 0–1 volume scale. When the media is muted, the fill level drops to 0 regardless of the stored volume value. When volumeAvailability is not "available", the HTML custom element receives native hidden, data-hidden, and disabled ARIA semantics; the React component returns null. This is independent of mutedAvailability, which controls whether the mute button is shown.

Styling

Use CSS custom properties to style the fill and pointer levels:

React renders a <div> element. Add a className to style it:

.volume-slider::before {
  width: var(--media-slider-fill);
}

Accessibility

Renders with role="slider" and an automatic aria-label that resolves to “Volume” from the active locale. Override with the label prop. Keyboard controls:

  • Arrow Left / Arrow Right: step by step increment
  • Page Up / Page Down: step by largeStep increment
  • Home: set volume to 0
  • End: set volume to max

Scroll wheel support:

  • Mouse wheel / trackpad scroll: adjusts volume by wheelStep increment (default 5)

Examples

Nest sub-components for full control over the slider’s DOM structure. This example includes a track, fill bar, draggable thumb, and a tooltip that shows the volume percentage on hover.

import { Container, createPlayer, MuteButton, VolumeSlider } from '@videojs/react';
import { Video, videoFeatures } from '@videojs/react/video';

const { Player } = createPlayer({ features: videoFeatures });

export default function WithParts() {
  return (
    <Player>
      <Container className="media-container">
        <Video src="https://stream.mux.com/BV3YZtogl89mg9VcNBhhnHm02Y34zI1nlMuMQfAbl3dM/highest.mp4" autoPlay muted playsInline loop />
        <MuteButton
          className="media-mute-button"
          render={(props, state) => <button {...props}>{state.muted ? 'Unmute' : 'Mute'}</button>}
        />
        <VolumeSlider.Root className="media-volume-slider">
          <VolumeSlider.Track className="media-slider-track">
            <VolumeSlider.Fill className="media-slider-fill" />
          </VolumeSlider.Track>
          <VolumeSlider.Thumb className="media-slider-thumb" />
          <VolumeSlider.Value type="pointer" className="media-slider-value" />
        </VolumeSlider.Root>
      </Container>
    </Player>
  );
}

API Reference

Root

Props

PropTypeDefaultDetails
disabledboolean
labelobject''
largeStepnumber
maxnumber
minnumber
orientation'horizontal' | 'vertical'
stepnumberDEFAULT_VOLUME_STEP
thumbAlignment'center' | 'edge'
valuenumber
wheelStepnumberDEFAULT_VOLUME_STEP

State

State is accessible via the render, className, and style props.

PropertyTypeDetails
valuenumber
fillPercentnumber
pointerPercentnumber
draggingboolean
pointingboolean
interactiveboolean
orientation'horizontal' | 'vertical'
disabledboolean
thumbAlignment'center' | 'edge'
volumenumber
mutedboolean
availabilityMediaFeatureAvailability
hiddenboolean

Data attributes

AttributeTypeDetails
data-availabilityMediaFeatureAvailability
data-hidden

CSS custom properties

VariableDetails
--media-slider-fill
--media-slider-pointer

Fill

Displays the filled portion from start to the current value.

Props

PropTypeDefaultDetails
classNamestring | ((state: SliderState) => string | undefined)
renderReactElement | ((props: HTMLProps, state: SliderState) => ReactElement | null)
styleCSSProperties | ((state: SliderState) => CSSProperties | undefined)

Preview

Positioning container for preview content that tracks the pointer along the slider.

Props

PropTypeDefaultDetails
classNamestring | ((state: SliderState) => string | undefined)
renderReactElement | ((props: HTMLProps, state: SliderState) => ReactElement | null)
styleCSSProperties | ((state: SliderState) => CSSProperties | undefined)

Data attributes

AttributeTypeDetails
data-dragging
data-pointing
data-interactive
data-orientation'horizontal' | 'vertical'
data-disabled

Thumb

Draggable handle for setting the slider value. Receives focus and handles keyboard interaction.

Props

PropTypeDefaultDetails
classNamestring | ((state: SliderState) => string | undefined)
renderReactElement | ((props: HTMLProps, state: SliderState) => ReactElement | null)
styleCSSProperties | ((state: SliderState) => CSSProperties | undefined)

Data attributes

AttributeTypeDetails
data-dragging
data-pointing
data-interactive
data-orientation'horizontal' | 'vertical'
data-disabled

Track

Contains the slider's visual track and interactive hit zone.

Props

PropTypeDefaultDetails
classNamestring | ((state: SliderState) => string | undefined)
renderReactElement | ((props: HTMLProps, state: SliderState) => ReactElement | null)
styleCSSProperties | ((state: SliderState) => CSSProperties | undefined)

Value

Displays a formatted text representation of the slider value. Renders an <output> element.

Props

PropTypeDefaultDetails
classNamestring | ((state: SliderState) => string | undefined)
format((value: number) => string)
renderReactElement | ((props: HTMLProps, state: SliderState) => ReactElement | null)
styleCSSProperties | ((state: SliderState) => CSSProperties | undefined)
type'current' | 'pointer'

Data attributes

AttributeTypeDetails
data-dragging
data-pointing
data-interactive
data-orientation'horizontal' | 'vertical'
data-disabled