WebVTT has no style settings of its own. Cues are styled with CSS, either from the web
page that plays the video or from STYLE blocks in the file. A
STYLE block holds a CSS style sheet, may not contain a blank line or
-->, and must come before the first cue.
Pseudo-elements and selectors
| Selector | Matches |
|---|---|
::cue | Every cue, as a whole |
::cue(selector) | Parts of a cue’s text that match the selector |
::cue-region | Every region |
::cue-region(selector) | Regions whose identifier matches an ID selector, such as ::cue-region(#scroll); no other selector matching is defined for it |
Inside ::cue(), the cue text is treated as a small document tree whose
elements are the tags of the cue text. These selectors work on it:
| Selector | Example | Matches |
|---|---|---|
| Type | ::cue(b) | The tags c, i, b, u, ruby, rt, v, lang |
| Class | ::cue(.loud) | Tags carrying that class |
| ID | ::cue(#intro-1) | The whole cue with that identifier |
| Attribute | ::cue(v[voice="Anna"]), ::cue([lang="fr"]) | A voice by name; a language span, or a cue whose track has that language |
:lang() | ::cue(:lang(ja)) | Text in that language |
Universal, :root | ::cue(*), ::cue(:root) | Every element; ::cue(:root) is the same as ::cue |
:past | ::cue(:past) | Tags that come before a timestamp whose time has passed |
:future | ::cue(:future) | Tags that come after a timestamp whose time has not yet come |
Plain text itself cannot be selected, only the tags around it. A cue with no
timestamp tags is neither :past nor :future.
Properties that apply
| Where | Properties |
|---|---|
::cue, ::cue-region | color, opacity, visibility, text-decoration, text-shadow, background (drawn behind the cue box), outline, font and its parts including line-height, white-space, text-combine-upright, ruby-position |
::cue(selector) | the same, plus transitions and animations; but with :past or :future in the selector, not font, white-space, text-combine-upright or ruby-position, so that revealing words never changes the layout |
All other properties are ignored, so a style sheet cannot move a cue: placement comes only from the cue settings.
| Default | Value |
|---|---|
| Font | 5% of the video’s height (5vh), sans-serif |
| Text colour | white, rgba(255,255,255,1) |
| Background | 80% black, rgba(0,0,0,0.8), behind the text |
| White space | pre-line: line breaks kept, runs of spaces collapsed |
| Italic, bold, underline tags | i: font-style: italic; b: font-weight: bold; u: text-decoration: underline |
| Ruby | ruby: display: ruby; rt: display: ruby-text, with the same 80% black background as the cue |
| Regions | an 80% black background, the same font and colour as cues, overflow: hidden, overflow-wrap: break-word, writing-mode: horizontal-tb, and a column flex layout that keeps the newest line at the bottom |
| Cue root | position: absolute, unicode-bidi: plaintext, overflow-wrap: break-word, text-wrap: balance; the text is wrapped in a box that carries the background |
These defaults are set in the user agent layer of the cascade, so any style sheet overrides them (W3C WebVTT section 7.4).
Style sheets in the file
- The sheets of
STYLEblocks apply only to the text tracks made from that file, never to other tracks of the same video. Their selectors apply to a notional document with one empty, unnamed element standing for the video, which is the element::cueand::cue-regionbelong to. - In the cascade the sheets from the file come after, and so win over rules of equal
specificity from, the style sheets of the page’s own document, in the order the
STYLEblocks appear. In the specification’s example, a page rule::cue { color:red }loses to::cue { color:lime }in the file, even though the page’sstyleelement comes later in the page. - A URL in a
STYLEblock, or in anything it refers to, resolves only if its scheme isdata; any other scheme is treated as if it failed. So@importof another file andbackground-imagefrom a web address do nothing, because they could make network requests as the viewer watches (a privacy risk).
Worked example
WEBVTT
STYLE
::cue {
background-color: rgba(0, 0, 0, 0.6);
font-family: "Helvetica Neue", sans-serif;
}
::cue(v[voice="Anna"]) { color: yellow; }
::cue(:future) { color: gray; }
00:01.000 --> 00:03.500
<v Anna>Where are we <00:02.500><c>going?</c>
c so that a selector can
reach it: it is grey until 2.5 seconds, because a rule on the c itself
beats the colour it inherits from the voice.