GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing developer.mozilla.org — Web Video Text Tracks Format (WebVTT) - Web APIs | MDN Web Video Text Tracks Format (WebVTT)
|
| Line | vertical omitted |
vertical:rl |
vertical:lr |
|---|---|---|---|
line:0 |
top | right | left |
line:-1 |
bottom | left | right |
line:0% |
top | right | left |
line:100% |
bottom | left | right |
positionIf vertical is not set, position specifies where the text will appear horizontally. If vertical is set, position specifies where the text will appear vertically. The value is a percentage between 0 and 100 inclusive.
| Position | vertical omitted |
vertical:rl |
vertical:lr |
|---|---|---|---|
position:0% |
left | top | top |
position:100% |
right | bottom | bottom |
sizeIf vertical is not set, size specifies the width of the text area. If vertical is set, size specifies the height of the text area. The value is a percentage between 0 and 100 inclusive.
| Size | vertical omitted |
vertical:rl |
vertical:lr |
|---|---|---|---|
size:100% |
full width | full height | full height |
size:50% |
half width | half height | half height |
alignSpecifies the alignment of the text. Text is aligned within the space given by the size cue setting if it is set.
| Align | vertical omitted |
vertical:rl |
vertical:lr |
|---|---|---|---|
align:start |
left | top | top |
align:center |
centered horizontally | centered vertically | centered vertically |
align:end |
right | bottom | bottom |
Here are a few examples. The first line demonstrates no settings. The second line might be used to overlay text on a sign or label. The third line might be used for a title. The last line might be used for an Asian language.
00:00:05.000 --> 00:00:10.000 00:00:05.000 --> 00:00:10.000 line:63% position:72% align:start 00:00:05.000 --> 00:00:10.000 line:0 position:20% size:60% align:start 00:00:05.000 --> 00:00:10.000 vertical:rt line:-1 align:end 00:00:05.000 --> 00:00:10.000 position:10%,line-left align:left size:31% 00:00:05.000 --> 00:00:10.000 position:90% align:right size:35% 00:00:05.000 --> 00:00:10.000 position:45%,line-right align:center size:90%
The payload is where the cue content is defined, such as the subtitle or closed caption text. It may contain newlines but cannot contain two consecutive newlines: that would create a blank line, which indicates the end of the block.
A cue text payload cannot contain the string -->, the ampersand character (&), or the less-than sign (<).
If needed, you can instead use a character reference such as the named character reference & for ampersand and < for less-than.
It is also recommended that you use the greater-than escape sequence > instead of the greater-than character (>) to avoid confusion with tags.
If you are using the WebVTT file for metadata these restrictions do not apply.
Note that all major browsers allow any character reference in cues, notes, or other text. Older browser versions may support only the following subset of named character references:
| Name | Character | Escape sequence |
|---|---|---|
| Ampersand | & |
& |
| Less-than | < |
< |
| Greater-than | > |
> |
| Left-to-right mark | none | ‎ |
| Right-to-left mark | none | ‏ |
| Non-breaking space | |
A number of tags, such as <b>, can be used for marking up and styling text within a cue.
However, if the WebVTT file is used in a <track> element where the attribute kind is chapters then you cannot use tags.
Timestamp tags are used to enable karaoke-style captions. The timestamp must be greater that the cue's start timestamp, greater than any previous timestamp in the cue payload, and less than the cue's end timestamp. The active text is the text between the timestamp and the next timestamp or to the end of the payload if there is not another timestamp in the payload. Any text before the active text in the payload is previous text. Any text beyond the active text is future text.
1 00:16.500 --> 00:18.500 When the moon <00:17.500>hits your eye 1 00:00:18.500 --> 00:00:20.500 Like a <00:19.000>big-a <00:19.500>pizza <00:20.000>pie 1 00:00:20.500 --> 00:00:21.500 That's <00:00:21.000>amore
The following tags are the HTML tags allowed in a cue and require opening and closing tags (e.g., <b>text</b>).
Text marked up with these tags can be formatted in STYLE blocks using the ::cue pseudo-element.
<i></i>)Italicize the contained text.
<i>text</i>
<b></b>)Bold the contained text.
<b>text</b>
<u></u>)Underline the contained text.
<u>text</u>
<c></c>)Add a class to the contained text for selection via CSS.
<c.classname>text</c>
<ruby></ruby>)Used with ruby text tags to display ruby characters (i.e., small annotative characters above other characters).
<ruby>WWW<rt>World Wide Web</rt>oui<rt>yes</rt></ruby>
<rt></rt>)Used with ruby tags to display ruby characters (i.e., small annotative characters above other characters).
<ruby>WWW<rt>World Wide Web</rt>oui<rt>yes</rt></ruby>
<v></v>)Similar to class tag, also used to style the contained text using CSS.
<v Bob>text</v>
<lang></lang>)Used to highlight text that has been marked up as belonging to a particular language or language variant using the BCP 47 language tag format.
<lang en-GB>English text as spoken in Great Britain!</lang>
NOTE blocks are optional sections that can be used to add comments to a WebVTT file. They are intended for those reading the file and are not seen by users. For example, you might use them to record author contact details, provide an overview of your structure, or add placeholders for cues that still need to be written.
They can be used anywhere in the WebVTT file after the header.
NOTE blocks may contain newlines but cannot contain two consecutive newlines: that would create a blank line, which indicates the end of the block.
A comment cannot contain the string -->, the ampersand character (&), or the less-than sign (<).
If you wish to use these characters, you need to instead use a character reference such as & for ampersand and < for less-than.
It is also recommended that you use the greater-than escape sequence (>) instead of the greater-than character (>) to avoid confusion with tags.
A comment consists of three parts:
NOTE.Here are some examples:
NOTE This is a single line comment NOTE This is a simple multi line comment NOTE One comment that is spanning more than one line. NOTE You can also make a comment across more than one line this way. NOTE TODO I might add a line to indicate work that still has to be done.
STYLE blocks are optional sections that can be used to embed CSS styling of cues within a WebVTT file.
Note that these are used to style the appearance and size of the cues, but not their position and layout, which are controlled by the Cue settings.
Note: WebVTT cues can also be matched by CSS styles loaded by the associated document embedding the video/audio element.
STYLE blocks must appear before any cue blocks in the file.
Each block consists of the following lines:
STYLE followed by zero or more space or tab characters, and then a newline.::cue pseudo-element.The block cannot contain the string -->.
It may contain newlines but cannot contain two consecutive newlines: that would create a blank line, which indicates the end of the block.
A simple WebVTT files with two STYLE blocks is shown below.
This uses ::cue to apply a text color to all cue text, and a different text color just to text that is tagged with <b></b> tags.
WEBVTT
STYLE
::cue {
background-image: linear-gradient(to bottom, dimgray, lightgray);
color: papayawhip;
}
/* Style blocks cannot use blank lines nor "dash dash greater than" */
NOTE comment blocks can be used between style blocks.
STYLE
::cue(b) {
color: peachpuff;
}
00:00:00.000 --> 00:00:10.000
- Hello <b>world</b>.
NOTE style blocks cannot appear after the first cue.
Note: There are live examples demonstrating many of the following cases in More cue styling examples in WebVTT API.
Match on all cue payload text using ::cue.
For example, the following STYLE block would match all cue text and color it yellow.
STYLE
::cue {
color: yellow;
}
Match cue text marked up with particular cue payload text tags, such as c, i, b, u, ruby, rt, v, and lang, by specifying the tag in ::cue() as a type selector.
For example, the following block would match cue payload text marked up with lang as yellow, and each of the other tags as red.
STYLE
::cue(c),
::cue(i),
::cue(b),
::cue(u),
::cue(ruby),
::cue(rt),
::cue(v) {
color: red;
}
::cue(lang) {
color: yellow;
}
Match all tags marked up using a class selector in ::cue().
The STYLE block in the following WebVTT file would match all the text after it, because all the tags have the myclass class.
WEBVTT
STYLE
::cue(.myclass) {
color: yellow;
}
00:00:00.000 --> 00:00:08.000
<c.myclass>Yellow!</c>
<i.myclass>Yellow!</i>
<u.myclass>Yellow!</u>
<b.myclass>Yellow!</b>
<u.myclass>Yellow!</u>
<ruby.myclass>Yellow! <rt.myclass>Yellow!</rt></ruby>
<v.myclass Kathryn>Yellow!</v>
<lang.myclass en>Yellow!</lang>
To select a particular tag and class you must specify both in ::cue():
::cue(b.myclass) {
color: yellow;
}
Cue payload text marked up with a particular tag and attribute can be matched using an attribute selector.
For example, consider the following WebVTT file, which has text marked up using the v and lang cue payload text tags, using attributes to specify the particular voice ("Salame") and languages.
WEBVTT
STYLE
::cue([lang="en-US"]) {
color: yellow;
}
::cue(lang[lang="en-GB"]) {
color: cyan;
}
::cue(v[voice="Salame"]) {
color: lime;
}
00:00:00.000 --> 00:00:08.000
Yellow!
00:00:08.000 --> 00:00:16.000
<lang en-GB>Cyan!</lang>
00:00:16.000 --> 00:00:24.000
I like <v Salame>lime.</v>
The previous example styled text for a particular language using attribute matching.
You can also match languages using the :lang() pseudo class, as demonstrated by the STYLE block below.
STYLE
::cue(:lang(en)) {
color: yellow;
}
::cue(:lang(en-GB)) {
color: cyan;
}
You can similarly match with the :past and :future pseudo-classes, to provide a karaoke-like experience.
video::cue(:past) {
color: yellow;
}
video::cue(:future) {
color: cyan;
}
Other pseudo-classes such as link, nth-last-child, and nth-child should work similarly.
Match against a particular cue id by specifying the id inside ::cue().
Note: At time of writing this does not appear to be supported in any of the main browsers.
For example, the following WebVTT file should style the cue with identifier cue1 in green.
WEBVTT
STYLE ::cue(#cue1) {
color: green;
}
cue1
00:00:00.000 --> 00:00:08.000
Green!
Note that escape sequences are used in WebVTT CSS in the same way as HTML pages. The below example shows how to escape spaces in a cue identifier:
WEBVTT
STYLE
::cue(#transcription\ credits) {
color: red;
}
transcription credits
00:04.000 --> 00:05.000
Transcribed by Célestes™
| Specification |
|---|
| WebVTT: The Web Video Text Tracks Format |
::cue and ::cue() pseudo-elements