Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Pseudo-elements

The ::cue pseudo-element

Reference for the CSS ::cue pseudo-element: style WebVTT captions and subtitles shown over video, with the supported properties and browser differences.

The ::cue pseudo-element styles WebVTT cues: the captions and subtitles that a browser draws over a <video> from a <track> element. The rule is written in the page that contains the video, selecting the video element.

Only a small group of properties is accepted, because the browser controls where and how big the cue box is. You can change color, background, font and shadows. With ::cue(selector) you style parts of a cue, such as voice spans or bold text in the WebVTT file.

CSS
video::cue {
  background: rgb(0 0 0 / 0.75);
  color: #ffe066;
}

Try it

Styled captions

Syntax

CSS
video::cue { }
video::cue(b) { }
video::cue(v[voice="Ada"]) { }
video::cue-region { }
Property Value
Applies to WebVTT cue boxes of the selected media element
Inherited Cues inherit from the media element, then from the cue's own settings
Animatable Not meaningful

Values

Syntax Description
::cue All cue text of the matching media.
::cue(selector) Cue parts matching a simple selector such as b, i, u, c.class, or v[voice="Name"].
::cue-region The region box that groups cues (limited support).

Allowed properties include color, opacity, visibility, background, outline, text-decoration, text-shadow, font and line-height, and white-space. Layout properties are ignored.

Usage notes

  • Needs a track. Without a <track> element that loaded and is showing, there is nothing to style.
  • Selectors are limited. The argument of ::cue() can only name WebVTT node types, classes and voices; it cannot use combinators or pseudo-classes.
  • Fonts are inherited. The cue starts from the font of the video element, so setting font-family on video also affects captions.
  • Browser-specific defaults. Browsers place and size cues on their own. Test in several browsers.
  • Keep it readable. Choose a solid or semi-transparent dark background; captions sit over changing images.
  • Styling inside the file. A WebVTT file can also carry STYLE blocks with ::cue rules, which keeps styling together with the captions.
  • Cross-origin tracks. Track files from another origin need CORS headers.

Browser support

Supported for basic properties in current browsers, but details, such as which selectors and properties are honored, differ between engines. Test your captions in each browser you target.