The text of a subtitle or caption cue may hold a small set of tags, written like HTML. Line breaks in the text are kept. Chapter cues hold plain text only, and metadata cues any text at all.
Classes and annotations
Any tag except a timestamp can carry classes, each after a full stop:
<c.yellow.bg_blue>, <v.loud Ben>. A class
name may not contain a space, tab, line break, &,
<, > or .. The annotation follows a space
or tab after the tag name and classes. It is made of annotation text, which may not
contain a line break, a bare & or >, and HTML character
references, which stand for one or two code points: <v Tom &
Jerry> is a voice named “Tom & Jerry”. A required annotation must contain at
least one character that is not a space or tab. A parser strips leading and trailing
white space from the annotation and replaces each run of white space inside it by a
single space.
| Default class | Effect |
|---|---|
white, bg_white | rgba(255,255,255,1) |
lime, bg_lime | rgba(0,255,0,1) (what captioners call green, as in 608/708) |
cyan, bg_cyan | rgba(0,255,255,1) |
red, bg_red | rgba(255,0,0,1) |
yellow, bg_yellow | rgba(255,255,0,1) |
magenta, bg_magenta | rgba(255,0,255,1) |
blue, bg_blue | rgba(0,0,255,1) |
black, bg_black | rgba(0,0,0,1) |
The plain name sets the color property and the bg_ name the
background-color property, in each case as a presentational hint, to the
value in the table (W3C WebVTT section 5; the table’s column heads are
“color value” and “background value”). On the cascade, the
specification says only: “the order of appearance determines the cascade of the
classes”. Its own example shows what that means: <c.yellow.bg_blue> is
yellow text on a blue background, and
<c.yellow.bg_blue.magenta.bg_black> is “magenta text on a black
background”, so where two colour classes of the same kind are on one tag, the later one
in the tag wins. Blue or black text
should not be used on the default dark background.
Characters
Plain text may not contain a bare < or &. Write them
with HTML character references: <, &,
>, and any other HTML named or numeric reference, such as
, ‎, ‏ or
♪ (♪). An & that does not start a reference
is kept as it is. The text may not contain -->.
How a parser reads damaged text
The cue text parsing rules (W3C WebVTT, section 6.4) never reject a cue because of its text. They build a tree of nodes as the tags are read, and recover as follows:
- A start tag for a name that is not
c,i,b,u,ruby,rt,vorlangis ignored (its text is kept), and so is the matching end tag. - An
rtstart tag is ignored unless the innermost open node is aruby. - An end tag closes the innermost open node only if it names that kind of node
(
c,i,b,u,ruby,rt,v,lang); otherwise it is ignored. The one exception: a</ruby>that arrives while anrtis the innermost node closes both thertand theruby. This is how the last</rt>can be left out. - Nodes still open at the end of the text are closed by the end of the text, so a missing end tag (such as the one of a voice covering the whole cue) is harmless.
- A tag that is not closed by
>before the end of the text is still returned: a start tag with the name, classes and annotation read so far, an end tag with its name so far, or a timestamp tag with the characters so far (which is then kept only if they form a valid timestamp). - A tag is read as a timestamp tag only if the first character after
<is an ASCII digit;</starts an end tag, a full stop a start tag with no name and classes, white space a start tag with no name and an annotation, and<>a start tag with an empty name. - A
vtag with no annotation becomes a voice with an empty name, and alangtag with no annotation gets an empty language. - Empty class names (as in
<c..a>) are dropped. - A timestamp tag is kept only if the whole tag is a valid timestamp (hours optional, as in the file’s own timing); with trailing characters it is ignored. Whether the time lies inside the cue or after the previous timestamp is not checked by the parser.
- Character references are consumed as HTML does in data text, not as part of an
attribute, so a legacy named reference without its closing semicolon is accepted.
In an annotation,
>is the additional allowed character. - An
&that does not begin a valid HTML character reference is kept as an ampersand, in text and in annotations. A<always starts a tag: everything up to the next>(or the end of the text) is read as one tag and dropped if it is not a known one, so a stray<in the text swallows what follows it.
The text of a chapter cue is extracted from the same tree: the title is the
concatenation of all the text nodes in document order, leaving out the text inside
rt (ruby text) and everything within it (section 6.6).
Worked example
00:00:10.000 --> 00:00:14.000
<v.singer Mia><c.yellow>♪</c> Twinkle, <00:00:11.000>twinkle, <00:00:12.000>little <00:00:13.000>star
00:00:15.000 --> 00:00:17.000
<ruby>東京<rt>とうきょう</rt></ruby> <lang en>(Tokyo)</lang>
:past and :future each would be wrapped in
<c>. The second cue shows ruby reading text above a place
name.