W3C

WebVTT: The Web Video Text Tracks Format

Draft Community Group Specification 04 April 2013

Latest editor's draft:
https://dvcs.w3.org/hg/text-tracks/raw-file/default/webvtt/webvtt.html
Editors:
Silvia Pfeiffer, NICTA
Ian Hickson, Google (previous editor)

Abstract

This is the specification of WebVTT, the Web Video Text Tracks format.

Status of This Document

This specification was published by the Text Tracks Community Group. It is not a W3C Standard nor is it on the W3C Standards Track. Please note that under the W3C Community Contributor License Agreement (CLA) there is a limited opt-out and other conditions apply. Learn more about W3C Community and Business Groups.

This specification was originally created by the WHATWG as a Living Standard and last published at http://dev.w3.org/html5/webvtt/.

Table of Contents

1. Introduction

This section is non-normative.

The WebVTT (Web Video Text Tracks) format is intended for marking up external text track resources.

The main use for WebVTT files is captioning video content. Here is a sample file that captions an interview:

WEBVTT

00:11.000 --> 00:13.000
<v Roger Bingham>We are in New York City

00:13.000 --> 00:16.000
<v Roger Bingham>We're actually at the Lucern Hotel, just down the street

00:16.000 --> 00:18.000
<v Roger Bingham>from the American Museum of Natural History

00:18.000 --> 00:20.000
<v Roger Bingham>And with me is Neil deGrasse Tyson

00:20.000 --> 00:22.000
<v Roger Bingham>Astrophysicist, Director of the Hayden Planetarium

00:22.000 --> 00:24.000
<v Roger Bingham>at the AMNH.

00:24.000 --> 00:26.000
<v Roger Bingham>Thank you for walking down here.

00:27.000 --> 00:30.000
<v Roger Bingham>And I want to do a follow-up on the last conversation we did.

00:30.000 --> 00:31.500 align:end size:50%
<v Roger Bingham>When we e-mailed—

00:30.500 --> 00:32.500 align:start size:50%
<v Neil deGrasse Tyson>Didn't we talk about enough in that conversation?

00:32.000 --> 00:35.500 align:end size:50%
<v Roger Bingham>No! No no no no; 'cos 'cos obviously 'cos

00:32.500 --> 00:33.500 align:start size:50%
<v Neil deGrasse Tyson><i>Laughs</i>

00:35.500 --> 00:38.000
<v Roger Bingham>You know I'm so excited my glasses are falling off here.

1.1 Cues with multiple lines

This section is non-normative.

Line breaks in cues are honored. User agents will also insert extra line breaks if necessary to fit the cue in the cue's width. In general, therefore, authors are encouraged to write cues all on one line except when a line break is definitely necessary, and to not manually line-wrap for aesthetic reasons alone.

These captions on a public service announcement video demonstrate line breaking:

WEBVTT

00:01.000 --> 00:04.000
Never drink liquid nitrogen.

00:05.000 --> 00:09.000
— It will perforate your stomach.
— You could die.

00:10.000 --> 00:14.000
The Organisation for Sample Public Service Announcements accepts no liability for the content of this advertisement, or for the consequences of any actions taken on the basis of the information provided.

The first cue is simple, it will probably just display on one line. The second will take two lines, one for each speaker. The third will wrap to fit the width of the video, possibly taking multiple lines. For example, the three cues could look like this:

           Never drink liquid nitrogen.

        — It will perforate your stomach.
                — You could die.

    The Organisation for Sample Public Service
    Announcements accepts no liability for the
    content of this advertisement, or for the
     consequences of any actions taken on the
        basis of the information provided.

If the width of the cues is smaller, the first two cues could wrap as well, as in the following example. Note how the second cue's explicit line break is still honored, however:

       Never drink
    liquid nitrogen.

  — It will perforate
      your stomach.
    — You could die.

  The Organisation for
  Sample Public Service
  Announcements accepts
  no liability for the
     content of this
  advertisement, or for
   the consequences of
  any actions taken on
    the basis of the
  information provided.

Also notice how the wrapping is done so as to keep the line lengths balanced.

1.2 Comments

This section is non-normative.

Comments can be included in WebVTT files.

Comments are just blocks that start with the word "NOTE" (followed by a space or newline). A comment ends at the first blank line.

Here, a one-line comment is used to note a possible problem with a cue.

WEBVTT

00:01.000 --> 00:04.000
Never drink liquid nitrogen.

NOTE I'm not sure the timing is right on the following cue.

00:05.000 --> 00:09.000
— It will perforate your stomach.
— You could die.

In this example, the author has written many comments.

WEBVTT

NOTE
This file was written by Jill. I hope
you enjoy reading it. Some things to
bear in mind:
- I was lip-reading, so the cues may
not be 100% accurate
- I didn't pay too close attention to
when the cues should start or end.

00:01.000 --> 00:04.000
Never drink liquid nitrogen.

NOTE check next cue

00:05.000 --> 00:09.000
— It will perforate your stomach.
— You could die.

NOTE end of file

1.3 Other features

This section is non-normative.

WebVTT also supports some less-often used features.

In this example, one of the cues has an identifier:

WEBVTT

00:00.000 --> 00:02.000
That's an, an, that's an L!

transcription-credit
00:04.000 --> 00:05.000
Transcribed by Celestials™

This allows a style sheet to specifically target that cue:

::cue(#transcription-credit) { color: red }

In this example, each cue says who is talking using voice spans. In the first cue, the span specifying the speaker is also annotated with two classes, "first" and "loud". In the third cue, there is also some italics text (not associated with a specific speaker). The last cue is annotated with just the class "loud".

WEBVTT

00:00.000 --> 00:02.000
<v.first.loud Esme>It's a blue apple tree!

00:02.000 --> 00:04.000
<v Mary>No way!

00:04.000 --> 00:06.000
<v Esme>Hee!</v> <i>laughter</i>

00:06.000 --> 00:08.000
<v.loud Mary>That's awesome!

Notice that as a special exception, the voice spans don't have to be closed if they cover the entire cue text.

Style sheets can style these spans:

::cue(v[voice="Esme"]) { color: blue }
::cue(v[voice="Mary"]) { color: green }
::cue(i) { font-style: italic }
::cue(.loud) { font-size: 2em }

2. Conformance

This section remains to be written. In the meantime, please see the HTML standard. [HTML5]

2.1 Dependencies

This specification relies upon the following terms defined in the HTML standard. [HTML5]

3. Data model

WebVTT cues are HTML text track cues that additionally consist of the following: [HTML5]

A writing direction

A writing direction, either horizontal (a line extends horizontally and is positioned vertically, with consecutive lines displayed below each other), vertical growing left (a line extends vertically and is positioned horizontally, with consecutive lines displayed to the left of each other), or vertical growing right (a line extends vertically and is positioned horizontally, with consecutive lines displayed to the right of each other).

If the writing direction is horizontal, then line position percentages are relative to the height of the video, and text position and size percentages are relative to the width of the video.

Otherwise, line position percentages are relative to the width of the video, and text position and size percentages are relative to the height of the video.

A snap-to-lines flag

A boolean indicating whether the line's position is a line position (positioned to a multiple of the line dimensions of the first line of the cue), or whether it is a percentage of the dimension of the video.

Cues whose text track cue snap-to-lines flag is set will be placed within the title-safe area on user agents that use overscan. Cues with the flag unset will be positioned as requested (modulo overlap avoidance if multiple cues are in the same place).

A line position

Either a number giving the position of the lines of the cue, to be interpreted as defined by the writing direction and snap-to-lines flag of the cue, or the special value auto, which means the position is to depend on the other active tracks.

A text track cue has a text track cue computed line position whose value is that returned by the following algorithm, which is defined in terms of the other aspects of the cue:

  1. If the text track cue line position is numeric, the text track cue snap-to-lines flag of the text track cue is not set, and the text track cue line position is negative or greater than 100, then return 100 and abort these steps.

  2. If the text track cue line position is numeric, return the value of the text track cue line position and abort these steps. (Either the text track cue snap-to-lines flag is set, so any value, not just those in the range 0..100, is valid, or the value is in the range 0..100 and is thus valid regardless of the value of that flag.)

  3. If the text track cue snap-to-lines flag of the text track cue is not set, return the value 100 and abort these steps. (The text track cue line position is the special value auto.)

  4. Let cue be the text track cue.

  5. If cue is not in a list of cues of a text track, or if that text track is not in the list of text tracks of a media element, return −1 and abort these steps.

  6. Let track be the text track whose list of cues the cue is in.

  7. Let n be the number of text tracks whose text track mode is showing and that are in the media element's list of text tracks before track.

  8. Increment n by one.

  9. Negate n.

  10. Return n.

A text position

A number giving the position of the text of the cue within each line, to be interpreted as a percentage of the video, as defined by the writing direction.

A size

A number giving the size of the box within which the text of each line of the cue is to be aligned, to be interpreted as a percentage of the video, as defined by the writing direction.

An alignment

An alignment for the text of each line of the cue, one of:

Start alignment
The text is aligned towards its start side.
Middle alignment
The text is aligned centered between its start and end sides.
End alignment
The text is aligned towards its end side.
Left alignment
The text is aligned to the left.
Right alignment
The text is aligned to the right.

Which sides are the start and end sides depends on the Unicode bidirectional algorithm and the writing direction. [BIDI]

The associated rules for updating the text track rendering of WebVTT text track cues are the rules for updating the display of WebVTT text tracks.

When a WebVTT text track cue whose active flag is set has its writing direction, snap-to-lines flag, line position, text position, size, alignment, or text change value, then the user agent must empty the text track cue display state, and then immediately run the text track's rules for updating the display of WebVTT text tracks.

4. The WebVTT file format

4.1 Syntax

A WebVTT file must consist of a WebVTT file body encoded as UTF-8 and labeled with the MIME type text/vtt. [RFC3629]

A WebVTT file body consists of the following components, in the following order:

  1. An optional U+FEFF BYTE ORDER MARK (BOM) character.
  2. The string "WEBVTT".
  3. Optionally, either a U+0020 SPACE character or a U+0009 CHARACTER TABULATION (tab) character followed by any number of characters that are not U+000A LINE FEED (LF) or U+000D CARRIAGE RETURN (CR) characters.
  4. Two or more WebVTT line terminators.
  5. Zero or more WebVTT cues and WebVTT comments separated from each other by two or more WebVTT line terminators.
  6. Zero or more WebVTT line terminators.

A WebVTT cue consists of the following components, in the given order:

  1. Optionally, a WebVTT cue identifier followed by a WebVTT line terminator.
  2. WebVTT cue timings.
  3. Optionally, one or more U+0020 SPACE characters or U+0009 CHARACTER TABULATION (tab) characters followed by WebVTT cue settings.
  4. A WebVTT line terminator.
  5. The cue payload: either WebVTT cue text, WebVTT chapter title text, or WebVTT metadata text, but it must not contain the substring "-->" (U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS, U+003E GREATER-THAN SIGN).
Note

A WebVTT cue corresponds to one piece of time-aligned text or data in the WebVTT file, for example one subtitle. The cue payload is the text or data associated with the cue.

WebVTT chapter title text is syntactically a subset of WebVTT cue text, and WebVTT cue text is syntactically a subset of WebVTT metadata text. Conformance checkers, when validating WebVTT files, may offer to restrict all cues to only having WebVTT chapter title text or WebVTT cue text as their cue payload; WebVTT metadata text cues are only useful for scripted applications (using the metadata text track kind).

A WebVTT file whose cues all have a cue payload that is WebVTT chapter title text is said to be a WebVTT file using chapter title text.

A WebVTT file whose cues all have a cue payload that is WebVTT cue text is said to be a WebVTT file using cue text. By definition, any file that is a WebVTT file using chapter title text is also a WebVTT file using cue text.

A WebVTT comment consists of the following components, in the given order:

  1. The string "NOTE".
  2. Optionally, the following components, in the given order:
    1. Either:
    2. Any sequence of zero or more characters other than U+000A LINE FEED (LF) characters and U+000D CARRIAGE RETURN (CR) characters, each optionally separated from the next by a WebVTT line terminator, except that the entire resulting string must not contain the substring "-->" (U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS, U+003E GREATER-THAN SIGN).
Note

A WebVTT comment is ignored by the parser.

A WebVTT line terminator consists of one of the following:

A WebVTT cue identifier is any sequence of one or more characters not containing the substring "-->" (U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS, U+003E GREATER-THAN SIGN), nor containing any U+000A LINE FEED (LF) characters or U+000D CARRIAGE RETURN (CR) characters.

Note

A WebVTT cue identifier can be used to reference a specific cue, for example from script or CSS.

The WebVTT cue timings part of a WebVTT cue consists of the following components, in the given order:

  1. A WebVTT timestamp representing the start time offset of the cue. The time represented by this WebVTT timestamp must be greater than or equal to the start time offsets of all previous cues in the file.
  2. One or more U+0020 SPACE characters or U+0009 CHARACTER TABULATION (tab) characters.
  3. The string "-->" (U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS, U+003E GREATER-THAN SIGN).
  4. One or more U+0020 SPACE characters or U+0009 CHARACTER TABULATION (tab) characters.
  5. A WebVTT timestamp representing the end time offset of the cue. The time represented by this WebVTT timestamp must be greater than the start time offset of the cue.
Note

The WebVTT cue timings give the start and end offsets of the WebVTT cue. Different cues can overlap. Cues are always listed ordered by their start time.

A WebVTT file whose cues all have an end time offset x greater than or equal to the end time offsets of all the cues whose start time offsets are less than x is said to be a WebVTT file using only nested cues.

The following example matches this definition:

WEBVTT

00:00.000 --> 01:24.000
Introduction

00:00.000 --> 00:44.000
Topics

00:44.000 --> 01:19.000
Presenters

01:24.000 --> 05:00.000
Scrolling Effects

01:35.000 --> 03:00.000
Achim's Demo

03:00.000 --> 05:00.000
Timeline Panel

Notice how you can express the cues in this WebVTT file as a tree structure:

  • WebVTT file
    • Introduction
      • Topics
      • Presenters
    • Scrolling Effects
      • Achim's Demo
      • Timeline Panel

If the file has cues that can't be expressed in this fashion, then they don't match the definition of a WebVTT file using only nested cues. For example:

WEBVTT

00:00.000 --> 01:00.000
The First Minute

00:30.000 --> 01:30.000
The Final Minute

In this ninety-second example, the two cues partly overlap, with the first ending before the second ends and the second starting before the first ends. This therefore is not a WebVTT file using only nested cues.

A WebVTT timestamp representing a time in seconds and fractions of a second is a WebVTT timestamp representing hours hours, minutes minutes, seconds seconds, and thousandths of a second seconds-frac, calculated as follows:

  1. Let seconds be the integer part of the time.

  2. Let seconds-frac be the fractional component of the time, expressed as the digits of the decimal fraction given to three decimal digits.

  3. If seconds is greater than 59, then let minutes be the integer component of seconds divided by sixty, and then let seconds be the remainder of dividing seconds divided by sixty. Otherwise, let minutes be zero.

  4. If minutes is greater than 59, then let hours be the integer component of minutes divided by sixty, and then let minutes be the remainder of dividing minutes divided by sixty. Otherwise, let hours be zero.

A WebVTT timestamp representing hours hours, minutes minutes, seconds seconds, and thousandths of a second seconds-frac, consists of the following components, in the given order:

  1. Optionally (required if hour is non-zero):
    1. Two or more ASCII digits, representing the hours as a base ten integer.
    2. A U+003A COLON character (:)
  2. Two ASCII digits, representing the minutes as a base ten integer in the range 0 ≤ minutes ≤ 59.
  3. A U+003A COLON character (:)
  4. Two ASCII digits, representing the seconds as a base ten integer in the range 0 ≤ seconds ≤ 59.
  5. A U+002E FULL STOP character (.).
  6. Three ASCII digits, representing the thousandths of a second seconds-frac as a base ten integer.

The WebVTT cue settings part of a WebVTT cue consists of zero or more of the following components, in any order, separated from each other by one or more U+0020 SPACE characters or U+0009 CHARACTER TABULATION (tab) characters. Each component must not be included more than once per WebVTT cue settings string.

Note

WebVTT cue settings give configuration options regarding the position and alignment of the cue. For example, it allows a cue to be aligned to the left or positioned at the top right.

A WebVTT vertical text cue setting consists of the following components, in the order given:

  1. The string "vertical".
  2. A U+003A COLON character (:).
  3. One of the following strings: "rl", "lr".
Note

A WebVTT vertical text cue setting configures the cue to use vertical text layout rather than horizontal text layout. Vertical text layout is sometimes used in Japanese, for example. The default is horizontal layout.

A WebVTT line position cue setting consists of the following components, in the order given:

  1. The string "line".

  2. A U+003A COLON character (:).

  3. Either:
    To represent a specific position relative to the video frame
    1. One or more ASCII digits.
    2. A U+0025 PERCENT SIGN character (%).
    To represent a line number
    1. Optionally a U+002D HYPHEN-MINUS character (-).
    2. One or more ASCII digits.
Note

A WebVTT line position cue setting configures the position of the cue. For horizontal cues, this is the vertical position. The position can be given either as a percentage, which gives the distance from the top of the frame, or as a line number. Line numbers are based on the size of the first line of the cue. Positive line numbers count from the top of the frame (the top line is numbered 0), negative line numbers from the bottom of the frame (the bottom line is numbered −1).

A WebVTT text position cue setting consists of the following components, in the order given:

  1. The string "position".

  2. A U+003A COLON character (:).
  3. One or more ASCII digits.
  4. A U+0025 PERCENT SIGN character (%).
Note

A WebVTT text position cue setting configures the position of the text in the direction orthogonal to the WebVTT line position cue setting. For horizontal cues, this is the horizontal position. The WebVTT text position cue setting is given as a percentage, calculated from the edge of the frame that the text begins (so for left-to-right English text, the left edge).

A WebVTT size cue setting consists of the following components, in the order given:

  1. The string "size".

  2. A U+003A COLON character (:).
  3. One or more ASCII digits.
  4. A U+0025 PERCENT SIGN character (%).
Note

A WebVTT size cue setting configures the size of the cue in the same direction as the WebVTT text position cue setting. For horizontal cues, this is the width of the cue. It is given as a percentage of the width of the frame.

A WebVTT alignment cue setting consists of the following components, in the order given:

  1. The string "align".

  2. A U+003A COLON character (:).
  3. One of the following strings: "start", "middle", "end", "left", "right"
Note

A WebVTT alignment cue setting configures the alignment of the text within the cue. The keywords are relative to the text direction; for left-to-right English text, "start" means left-aligned.

WebVTT metadata text consists of any sequence of zero or more characters other than U+000A LINE FEED (LF) characters and U+000D CARRIAGE RETURN (CR) characters, each optionally separated from the next by a WebVTT line terminator. (In other words, any text that does not have two consecutive WebVTT line terminators and does not start or end with a WebVTT line terminator.)

WebVTT chapter title text consists of zero or more of the following, each optionally separated from the next by a WebVTT line terminator:

WebVTT cue text consists of zero or more WebVTT cue components, in any order, each optionally separated from the next by a WebVTT line terminator.

The WebVTT cue components are:

WebVTT cue internal text consists of an optional WebVTT line terminator, followed by zero or more WebVTT cue components, in any order, each optionally followed by a WebVTT line terminator.

A WebVTT cue class span consists of a WebVTT cue span start tag "c" that disallows an annotation, WebVTT cue internal text representing cue text, and a WebVTT cue span end tag "c".

A WebVTT cue italics span consists of a WebVTT cue span start tag "i" that disallows an annotation, WebVTT cue internal text representing the italicized text, and a WebVTT cue span end tag "i".

A WebVTT cue bold span consists of a WebVTT cue span start tag "b" that disallows an annotation, WebVTT cue internal text representing the boldened text, and a WebVTT cue span end tag "b".

A WebVTT cue underline span consists of a WebVTT cue span start tag "u" that disallows an annotation, WebVTT cue internal text representing the underlined text, and a WebVTT cue span end tag "u".

A WebVTT cue ruby span consists of the following components, in the order given:

  1. A WebVTT cue span start tag "ruby" that disallows an annotation.
  2. One or more occurrences of the following group of components, in the order given:
    1. WebVTT cue internal text, representing the ruby base.
    2. A WebVTT cue span start tag "rt" that disallows an annotation.
    3. A WebVTT cue ruby text span: WebVTT cue internal text, representing the ruby text component of the ruby annotation.
    4. A WebVTT cue span end tag "rt". If this is the last occurrence of this group of components in the WebVTT cue ruby span, then this last end tag string may be omitted.
  3. If the last end tag string was not omitted: Optionally, a WebVTT line terminator.
  4. If the last end tag string was not omitted: Zero or more U+0020 SPACE characters or U+0009 CHARACTER TABULATION (tab) characters, each optionally followed by a WebVTT line terminator.
  5. A WebVTT cue span end tag "ruby".

A WebVTT cue voice span consists of the following components, in the order given:

  1. A WebVTT cue span start tag "v" that requires an annotation; the annotation represents the name of the voice.
  2. WebVTT cue internal text.
  3. A WebVTT cue span end tag "v". If this WebVTT cue voice span is the only component of its WebVTT cue text sequence, then the end tag may be omitted for brevity.

A WebVTT cue language span consists of the following components, in the order given:

  1. A WebVTT cue span start tag "lang" that requires an annotation; the annotation represents the language of the following component, and must be a valid BCP 47 language tag. [BCP47]
  2. WebVTT cue internal text.
  3. A WebVTT cue span end tag "lang".

A WebVTT cue span start tag has a tag name and either requires or disallows an annotation, and consists of the following components, in the order given:

  1. A U+003C LESS-THAN SIGN character (<).
  2. The tag name.
  3. Zero or more occurrences of the following sequence:
    1. U+002E FULL STOP character (.)
    2. One or more characters other than U+0009 CHARACTER TABULATION (tab) characters, U+000A LINE FEED (LF) characters, U+000D CARRIAGE RETURN (CR) characters, U+0020 SPACE characters, U+0026 AMPERSAND characters (&), U+003C LESS-THAN SIGN characters (<), U+003E GREATER-THAN SIGN characters (>), and U+002E FULL STOP characters (.), representing a class that describes the cue span's significance.
  4. If the start tag requires an annotation: a U+0020 SPACE character or a U+0009 CHARACTER TABULATION (tab) character, followed by one or more of the following components, the concatenation of their representations having a value that contains at least one character other than U+0020 SPACE and U+0009 CHARACTER TABULATION (tab) characters:
  5. A U+003E GREATER-THAN SIGN character (>).

A WebVTT cue span end tag has a tag name and consists of the following components, in the order given:

  1. A U+003C LESS-THAN SIGN character (<).
  2. U+002F SOLIDUS character (/).
  3. The tag name.
  4. A U+003E GREATER-THAN SIGN character (>).

A WebVTT cue timestamp consists of a U+003C LESS-THAN SIGN character (<), followed by a WebVTT timestamp representing the time that the given point in the cue becomes active, followed by a U+003E GREATER-THAN SIGN character (>). The time represented by the WebVTT timestamp must be greater than the times represented by any previous WebVTT cue timestamps in the cue, as well as greater than the cue's start time offset, and less than the cue's end time offset.

A WebVTT cue text span consists of one or more characters other than U+000A LINE FEED (LF) characters, U+000D CARRIAGE RETURN (CR) characters, U+0026 AMPERSAND characters (&), and U+003C LESS-THAN SIGN characters (<).

WebVTT cue span start tag annotation text consists of one or more characters other than U+000A LINE FEED (LF) characters, U+000D CARRIAGE RETURN (CR) characters, U+0026 AMPERSAND characters (&), and U+003E GREATER-THAN SIGN characters (>).

A WebVTT cue amp escape is the five character string "&amp;".

A WebVTT cue lt escape is the four character string "&lt;".

A WebVTT cue gt escape is the four character string "&gt;".

A WebVTT cue lrm escape is the five character string "&lrm;".

A WebVTT cue rlm escape is the five character string "&rlm;".

A WebVTT cue nbsp escape is the six character string "&nbsp;".

4.2 Parsing

A WebVTT parser, given an input byte stream and a text track list of cues output, must decode the byte stream as UTF-8, with error handling, and then must parse the resulting string according to the WebVTT parser algorithm below. This results in text track cues being added to output. [RFC3629]

A WebVTT parser, specifically its conversion and parsing steps, is typically run asynchronously, with the input byte stream being updated incrementally as the resource is downloaded; this is called an incremental WebVTT parser.

A WebVTT parser verifies a file signature before parsing the provided byte stream. If the stream lacks this WebVTT file signature, then the parser aborts.

The WebVTT parser algorithm is as follows:

  1. Let input be the string being parsed, after conversion to Unicode, and with the following transformations applied:

    • Replace all U+0000 NULL characters by U+FFFD REPLACEMENT CHARACTERs.

    • Replace each U+000D CARRIAGE RETURN U+000A LINE FEED (CRLF) character pair by a single U+000A LINE FEED (LF) character.

    • Replace all remaining U+000D CARRIAGE RETURN characters by U+000A LINE FEED (LF) characters.

  2. Let position be a pointer into input, initially pointing at the start of the string. In an incremental WebVTT parser, when this algorithm (or further algorithms that it uses) moves the position pointer, the user agent must wait until appropriate further characters from the byte stream have been added to input before moving the pointer, so that the algorithm never reads past the end of the input string. Once the byte stream has ended, and all characters have been added to input, then the position pointer may, when so instructed by the algorithms, be moved past the end of input.

  3. If the character indicated by position is a U+FEFF BYTE ORDER MARK (BOM) character, advance position to the next character in input.

  4. Let line be a string variable. Unset the already collected line flag.
  5. Collect a sequence of characters that are not U+000A LINE FEED (LF) characters. Let line be those characters, if any.

  6. If line is less than six characters long, then abort these steps. The file does not start with the correct WebVTT file signature and was therefore not successfully processed.

  7. If line is exactly six characters long but does not exactly equal "WEBVTT", then abort these steps. The file does not start with the correct WebVTT file signature and was therefore not successfully processed.

  8. If line is more than six characters long but the first six characters do not exactly equal "WEBVTT", or the seventh character is neither a U+0020 SPACE character nor a U+0009 CHARACTER TABULATION (tab) character, then abort these steps. The file does not start with the correct WebVTT file signature and was therefore not successfully processed.

  9. If position is past the end of input, then abort these steps. The file was successfully processed, but it contains no useful data and so no text track cues where added to output.

  10. The character indicated by position is a U+000A LINE FEED (LF) character. Advance position to the next character in input.

  11. Header: Collect a sequence of characters that are not U+000A LINE FEED (LF) characters. Let line be those characters, if any.

  12. If position is past the end of input, then jump to the step labeled end.

  13. The character indicated by position is a U+000A LINE FEED (LF) character. Advance position to the next character in input.

  14. If line contains the three-character substring "-->" (U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS, U+003E GREATER-THAN SIGN), then set the already collected line flag and jump to the step labeled cue loop.

  15. If line is not the empty string, then jump back to the step labeled header.

  16. Cue loop: If the already collected line flag is set, then jump to the step labeled cue creation.

  17. Collect a sequence of characters that are U+000A LINE FEED (LF) characters.

  18. Collect a sequence of characters that are not U+000A LINE FEED (LF) characters. Let line be those characters, if any.

  19. If line is the empty string, then jump to the step labeled end. (In such a case, position is also forcibly past the end of input.)

  20. Cue creation: Let cue be a new text track cue.

  21. Let cue's text track cue identifier be the empty string.

  22. Let cue's text track cue pause-on-exit flag be false.

  23. Let cue's Text track cue writing direction be horizontal.

  24. Let cue's text track cue snap-to-lines flag be true.

  25. Let cue's text track cue line position be auto.

  26. Let cue's text track cue text position be 50.

  27. Let cue's text track cue size be 100.

  28. Let cue's Text track cue alignment be middle alignment.

  29. Let cue's text track cue text be the empty string.

  30. If line contains the three-character substring "-->" (U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS, U+003E GREATER-THAN SIGN), then jump to the step labeled timings below.

  31. Let cue's text track cue identifier be line.

  32. If position is past the end of input, then discard cue and jump to the step labeled end.

  33. If the character indicated by position is a U+000A LINE FEED (LF) character, advance position to the next character in input.

  34. Collect a sequence of characters that are not U+000A LINE FEED (LF) characters. Let line be those characters, if any.

  35. If line is the empty string, then discard cue and jump to the step labeled cue loop.

  36. Timings: Unset the already collected line flag.

  37. Collect WebVTT cue timings and settings from line, using cue for the results. If that fails, jump to the step labeled bad cue.

  38. Let cue text be the empty string.

  39. Cue text loop: If position is past the end of input, then jump to the step labeled cue text processing.

  40. If the character indicated by position is a U+000A LINE FEED (LF) character, advance position to the next character in input.

  41. Collect a sequence of characters that are not U+000A LINE FEED (LF) characters. Let line be those characters, if any.

  42. If line is the empty string, then jump to the step labeled cue text processing.

  43. If line contains the three-character substring "-->" (U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS, U+003E GREATER-THAN SIGN), then set the already collected line flag and jump to the step labeled cue text processing.

  44. If cue text is not empty, append a U+000A LINE FEED (LF) character to cue text.

  45. Let cue text be the concatenation of cue text and line.

  46. Return to the step labeled cue text loop.

  47. Cue text processing: Let the text track cue text of cue be cue text, and let the rules for rendering the cue in isolation be the rules for interpreting WebVTT cue text.

  48. Add cue to the text track list of cues output.

  49. Jump to the step labeled cue loop.

  50. Bad cue: Discard cue.

  51. Bad cue loop: If position is past the end of input, then jump to the step labeled end.

  52. If the character indicated by position is a U+000A LINE FEED (LF) character, advance position to the next character in input.

  53. Collect a sequence of characters that are not U+000A LINE FEED (LF) characters. Let line be those characters, if any.

  54. If line contains the three-character substring "-->" (U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS, U+003E GREATER-THAN SIGN), then set the already collected line flag and jump to the step labeled cue loop.

  55. If line is the empty string, then jump to the step labeled cue loop.

  56. Otherwise, jump to the step labeled bad cue loop.

  57. End: The file has ended. Abort these steps. The WebVTT parser has finished. The file was successfully processed.

When the algorithm above requires that the user agent Collect WebVTT cue timings and settings from a string input for a text track cue cue, the user agent must run the following algorithm.

  1. Let input be the string being parsed.

  2. Let position be a pointer into input, initially pointing at the start of the string.

  3. Skip whitespace.

  4. Collect a WebVTT timestamp. If that algorithm fails, then abort these steps and return failure. Otherwise, let cue's text track cue start time be the collected time.

  5. Skip whitespace.

  6. If the character at position is not a U+002D HYPHEN-MINUS character (-) then abort these steps and return failure. Otherwise, move position forwards one character.

  7. If the character at position is not a U+002D HYPHEN-MINUS character (-) then abort these steps and return failure. Otherwise, move position forwards one character.

  8. If the character at position is not a U+003E GREATER-THAN SIGN character (>) then abort these steps and return failure. Otherwise, move position forwards one character.

  9. Skip whitespace.

  10. Collect a WebVTT timestamp. If that algorithm fails, then abort these steps and return failure. Otherwise, let cue's text track cue end time be the collected time.

  11. Let remainder be the trailing substring of input starting at position.

  12. Parse the WebVTT settings given by remainder for cue.

When the user agent is to Parse the WebVTT settings given by a string input for a text track cue cue, the user agent must run the following steps:

  1. Let settings be the result of splitting input on spaces.

  2. For each token setting in the list settings, run the following substeps:

    1. If setting does not contain a U+003A COLON character (:), or if the first U+003A COLON character (:) in setting is either the first or last character of setting, then jump to the step labeled next setting.

    2. Let name be the leading substring of setting up to and excluding the first U+003A COLON character (:) in that string.

    3. Let value be the trailing substring of setting starting from the character immediately after the first U+003A COLON character (:) in that string.

    4. Run the appropriate substeps that apply for the value of name, as follows:

      If name is a case-sensitive match for "vertical"
      1. If value is a case-sensitive match for the string "rl", then let cue's Text track cue writing direction be vertical growing left.

      2. Otherwise, if value is a case-sensitive match for the string "lr", then let cue's Text track cue writing direction be vertical growing right.

      If name is a case-sensitive match for "line"
      1. If value contains any characters other than U+002D HYPHEN-MINUS characters (-), U+0025 PERCENT SIGN characters (%), and ASCII digits, then jump to the step labeled next setting.

      2. If value does not contain at least one ASCII digit, then jump to the step labeled next setting.

      3. If any character in value other than the first character is a U+002D HYPHEN-MINUS character (-), then jump to the step labeled next setting.

      4. If any character in value other than the last character is a U+0025 PERCENT SIGN character (%), then jump to the step labeled next setting.

      5. If the first character in value is a U+002D HYPHEN-MINUS character (-) and the last character in value is a U+0025 PERCENT SIGN character (%), then jump to the step labeled next setting.

      6. Ignoring the trailing percent sign, if any, interpret value as a (potentially signed) integer, and let number be that number.

      7. If the last character in value is a U+0025 PERCENT SIGN character (%), but number is not in the range 0 ≤ number ≤ 100, then jump to the step labeled next setting.

      8. Let cue's text track cue line position be number.

      9. If the last character in value is a U+0025 PERCENT SIGN character (%), then let cue's text track cue snap-to-lines flag be false. Otherwise, let it be true.

      If name is a case-sensitive match for "position"
      1. If value contains any characters other than U+0025 PERCENT SIGN characters (%) and ASCII digits, then jump to the step labeled next setting.

      2. If value does not contain at least one ASCII digit, then jump to the step labeled next setting.

      3. If any character in value other than the last character is a U+0025 PERCENT SIGN character (%), then jump to the step labeled next setting.

      4. If the last character in value is not a U+0025 PERCENT SIGN character (%), then jump to the step labeled next setting.

      5. Ignoring the trailing percent sign, interpret value as an integer, and let number be that number.

      6. If number is not in the range 0 ≤ number ≤ 100, then jump to the step labeled next setting.

      7. Let cue's text track cue text position be number.

      If name is a case-sensitive match for "size"
      1. If value contains any characters other than U+0025 PERCENT SIGN characters (%) and ASCII digits, then jump to the step labeled next setting.

      2. If value does not contain at least one ASCII digit, then jump to the step labeled next setting.

      3. If any character in value other than the last character is a U+0025 PERCENT SIGN character (%), then jump to the step labeled next setting.

      4. If the last character in value is not a U+0025 PERCENT SIGN character (%), then jump to the step labeled next setting.

      5. Ignoring the trailing percent sign, interpret value as an integer, and let number be that number.

      6. If number is not in the range 0 ≤ number ≤ 100, then jump to the step labeled next setting.

      7. Let cue's text track cue size be number.

      If name is a case-sensitive match for "align"
      1. If value is a case-sensitive match for the string "start", then let cue's Text track cue alignment be start alignment.

      2. If value is a case-sensitive match for the string "middle", then let cue's Text track cue alignment be middle alignment.

      3. If value is a case-sensitive match for the string "end", then let cue's Text track cue alignment be end alignment.

      4. If value is a case-sensitive match for the string "left", then let cue's Text track cue alignment be left alignment.

      5. If value is a case-sensitive match for the string "right", then let cue's Text track cue alignment be right alignment.

    5. Next setting: Continue to the next token, if any.

When this specification says that a user agent is to Collect a WebVTT timestamp, the user agent must run the following steps:

  1. Let input and position be the same variables as those of the same name in the algorithm that invoked these steps.

  2. Let most significant units be minutes.

  3. If position is past the end of input, return an error and abort these steps.

  4. If the character indicated by position is not an ASCII digit, then return an error and abort these steps.

  5. Collect a sequence of characters that are ASCII digits, and let string be the collected substring.

  6. Interpret string as a base-ten integer. Let value1 be that integer.

  7. If string is not exactly two characters in length, or if value1 is greater than 59, let most significant units be hours.

  8. If position is beyond the end of input or if the character at position is not a U+003A COLON character (:), then return an error and abort these steps. Otherwise, move position forwards one character.

  9. Collect a sequence of characters that are ASCII digits, and let string be the collected substring.

  10. If string is not exactly two characters in length, return an error and abort these steps.

  11. Interpret string as a base-ten integer. Let value2 be that integer.

  12. If most significant units is hours, or if position is not beyond the end of input and the character at position is a U+003A COLON character (:), run these substeps:

    1. If position is beyond the end of input or if the character at position is not a U+003A COLON character (:), then return an error and abort these steps. Otherwise, move position forwards one character.

    2. Collect a sequence of characters that are ASCII digits, and let string be the collected substring.

    3. If string is not exactly two characters in length, return an error and abort these steps.

    4. Interpret string as a base-ten integer. Let value3 be that integer.

    Otherwise (if most significant units is not hours, and either position is beyond the end of input, or the character at position is not a U+003A COLON character (:)), let value3 have the value of value2, then value2 have the value of value1, then let value1 equal zero.

  13. If position is beyond the end of input or if the character at position is not a U+002E FULL STOP character (.), then return an error and abort these steps. Otherwise, move position forwards one character.

  14. Collect a sequence of characters that are ASCII digits, and let string be the collected substring.

  15. If string is not exactly three characters in length, return an error and abort these steps.

  16. Interpret string as a base-ten integer. Let value4 be that integer.

  17. If value2 is greater than 59 or if value3 is greater than 59, return an error and abort these steps.

  18. Let result be value1×60×60 + value2×60 + value3 + value4∕1000.

  19. Return result.

4.3 WebVTT cue text parsing rules

A WebVTT Node Object is a conceptual construct used to represent components of WebVTT cue text so that its processing can be described without reference to the underlying syntax.

There are two broad classes of WebVTT Node Objects: WebVTT Internal Node Objects and WebVTT Leaf Node Objects.

WebVTT Internal Node Objects are those that can contain further WebVTT Node Objects. They are conceptually similar to elements in HTML or the DOM. WebVTT Internal Node Objects have an ordered list of child WebVTT Node Objects. The WebVTT Internal Node Object is said to be the parent of the children. Cycles do not occur; the parent-child relationships so constructed form a tree structure. WebVTT Internal Node Objects also have an ordered list of class names, known as their applicable classes, and a language, known as their applicable language, which is to be interpreted as a BCP 47 language code. [BCP47]

There are several concrete classes of WebVTT Internal Node Objects:

Lists of WebVTT Node Objects

These are used as root nodes for trees of WebVTT Node Objects.

WebVTT Class Objects

These represent spans of text (a WebVTT cue class span) in WebVTT cue text, and are used to annotate parts of the cue with applicable classes without implying further meaning (such as italics or bold).

WebVTT Italic Objects

These represent spans of italic text (a WebVTT cue italics span) in WebVTT cue text.

WebVTT Bold Objects

These represent spans of bold text (a WebVTT cue bold span) in WebVTT cue text.

WebVTT Underline Objects

These represent spans of underline text (a WebVTT cue underline span) in WebVTT cue text.

WebVTT Ruby Objects

These represent spans of ruby (a WebVTT cue ruby span) in WebVTT cue text.

WebVTT Ruby Text Objects

These represent spans of ruby text (a WebVTT cue ruby text span) in WebVTT cue text.

WebVTT Voice Objects

These represent spans of text associated with a specific voice (a WebVTT cue voice span) in WebVTT cue text. A WebVTT Voice Object has a value, which is the name of the voice.

WebVTT Language Objects

These represent spans of text (a WebVTT cue language span) in WebVTT cue text, and are used to annotate parts of the cue where the applicable language might be different than the surrounding text's, without implying further meaning (such as italics or bold).

WebVTT Leaf Node Objects are those that contain data, such as text, and cannot contain child WebVTT Node Objects.

There are two concrete classes of WebVTT Leaf Node Objects:

WebVTT Text Objects

A fragment of text. A WebVTT Text Object has a value, which is the text it represents.

WebVTT Timestamp Objects

A timestamp. A WebVTT Timestamp Object has a value, in seconds and fractions of a second, which is the time represented by the timestamp.

To parse a string input supposedly containing WebVTT cue text, user agents must use the following algorithm. This algorithm returns a List of WebVTT Node Objects.

  1. Let input be the string being parsed.

  2. Let position be a pointer into input, initially pointing at the start of the string.

  3. Let result be a List of WebVTT Node Objects, initially empty.

  4. Let current be the WebVTT Internal Node Object result.

  5. Let language stack be a stack of language codes, initially empty.

  6. Loop: If position is past the end of input, return result and abort these steps.

  7. Let token be the result of invoking the WebVTT cue text tokenizer.

  8. Run the appropriate steps given the type of token:

    If token is a string
    1. Create a WebVTT Text Object whose value is the value of the string token token.

    2. Append the newly created WebVTT Text Object to current.

    If token is a start tag

    How the start tag token token is processed depends on its tag name, as follows:

    If the tag name is "c"

    Attach a WebVTT Class Object.

    If the tag name is "i"

    Attach a WebVTT Italic Object.

    If the tag name is "b"

    Attach a WebVTT Bold Object.

    If the tag name is "u"

    Attach a WebVTT Underline Object.

    If the tag name is "ruby"

    Attach a WebVTT Ruby Object.

    If the tag name is "rt"

    If current is a WebVTT Ruby Object, then attach a WebVTT Ruby Text Object.

    If the tag name is "v"

    Attach a WebVTT Voice Object, and set its value to the token's annotation string, or the empty string if there is no annotation string.

    If the tag name is "lang"

    Push the value of the token's annotation string, or the empty string if there is no annotation string, onto the language stack; then attach a WebVTT Language Object.

    Otherwise

    Ignore the token.

    When the steps above say to attach a WebVTT Internal Node Object of a particular concrete class, the user agent must run the following steps:

    1. Create a new WebVTT Internal Node Object of the specified concrete class.

    2. Set the new object's list of applicable classes to the list of classes in the token, excluding any classes that are the empty string.

    3. Set the new object's applicable language to the top entry on the language stack, if the stack is not empty.

    4. Append the newly created node object to current.

    5. Let current be the newly created node object.

    If token is an end tag

    If any of the following conditions is true, then let current be the parent node of current.

    Otherwise, if the tag name of the end tag token token is "lang" and current is a WebVTT Language Object, then let current be the parent node of current, and pop the top value from the language stack.

    Otherwise, if the tag name of the end tag token token is "ruby" and current is a WebVTT Ruby Text Object, then let current be the parent node of the parent node of current.

    Otherwise, ignore the token.

    If token is a timestamp tag
    1. Let input be the tag value.

    2. Let position be a pointer into input, initially pointing at the start of the string.

    3. Collect a WebVTT timestamp.

    4. If that algorithm does not fail, and if position now points at the end of input (i.e. there are no trailing characters after the timestamp), then create a WebVTT Timestamp Object whose value is the collected time, then append it to current.

      Otherwise, ignore the token.

  9. Jump to the step labeled loop.

The WebVTT cue text tokenizer is as follows. It emits a token, which is either a string (whose value is a sequence of characters), a start tag (with a tag name, a list of classes, and optionally an annotation), an end tag (with a tag name), or a timestamp tag (with a tag value).

  1. Let input and position be the same variables as those of the same name in the algorithm that invoked these steps.

  2. Let tokenizer state be WebVTT data state.

  3. Let result be the empty string.

  4. Let buffer be the empty string.

  5. Let classes be an empty list.

  6. Loop: If position is past the end of input, let c be an end-of-file marker. Otherwise, let c be the character in input pointed to by position.

    Note

    An end-of-file marker is not a Unicode character, it is used to end the tokenizer.

  7. Jump to the state given by tokenizer state:

    WebVTT data state

    Jump to the entry that matches the value of c:

    U+0026 AMPERSAND (&)

    Set buffer to c, set tokenizer state to the WebVTT escape state, and jump to the step labeled next.

    U+003C LESS-THAN SIGN (<)

    If result is the empty string, then set tokenizer state to the WebVTT tag state and jump to the step labeled next.

    Otherwise, return a string token whose value is result and abort these steps.

    End-of-file marker

    Return a string token whose value is result and abort these steps.

    Anything else

    Append c to result and jump to the step labeled next.

    WebVTT escape state

    Jump to the entry that matches the value of c:

    U+0026 AMPERSAND (&)

    Append buffer to result, set buffer to c, and jump to the step labeled next.

    Alphanumeric ASCII characters

    Append c to buffer and jump to the step labeled next.

    U+003B SEMICOLON character (;)

    First, examine the value of buffer:

    If buffer is the string "&amp", then append a U+0026 AMPERSAND character (&) to result.

    If buffer is the string "&lt", then append a U+003C LESS-THAN SIGN character (<) to result.

    If buffer is the string "&gt", then append a U+003E GREATER-THAN SIGN character (>) to result.

    If buffer is the string "&lrm", then append a U+200E LEFT-TO-RIGHT MARK character to result.

    If buffer is the string "&rlm", then append a U+200F RIGHT-TO-LEFT MARK character to result.

    If buffer is the string "&nbsp", then append a U+00A0 NO-BREAK SPACE character to result.

    Otherwise, append buffer followed by a U+003B SEMICOLON character (;) to result.

    Then, in any case, set tokenizer state to the WebVTT data state, and jump to the step labeled next.

    U+003C LESS-THAN SIGN (<)
    End-of-file marker

    Append buffer to result, return a string token whose value is result, and abort these steps.

    Anything else

    Append buffer to result, append c to result, set tokenizer state to the WebVTT data state, and jump to the step labeled next.

    WebVTT tag state

    Jump to the entry that matches the value of c:

    U+0009 CHARACTER TABULATION (tab) character
    U+000A LINE FEED (LF) character
    U+000C FORM FEED (FF) character
    U+0020 SPACE character

    Set tokenizer state to the WebVTT start tag annotation state, and jump to the step labeled next.

    U+002E FULL STOP character (.)

    Set tokenizer state to the WebVTT start tag class state, and jump to the step labeled next.

    U+002F SOLIDUS character (/)

    Set tokenizer state to the WebVTT end tag state, and jump to the step labeled next.

    ASCII digits

    Set result to c, set tokenizer state to the WebVTT timestamp tag state, and jump to the step labeled next.

    U+003E GREATER-THAN SIGN character (>)

    Advance position to the next character in input, then jump to the next "end-of-file marker" entry below.

    End-of-file marker

    Return a start tag whose tag name is the empty string, with no classes and no annotation, and abort these steps.

    Anything else

    Set result to c, set tokenizer state to the WebVTT start tag state, and jump to the step labeled next.

    WebVTT start tag state

    Jump to the entry that matches the value of c:

    U+0009 CHARACTER TABULATION (tab) character
    U+000C FORM FEED (FF) character
    U+0020 SPACE character

    Set tokenizer state to the WebVTT start tag annotation state, and jump to the step labeled next.

    U+000A LINE FEED (LF) character

    Set buffer to c, set tokenizer state to the WebVTT start tag annotation state, and jump to the step labeled next.

    U+002E FULL STOP character (.)

    Set tokenizer state to the WebVTT start tag class state, and jump to the step labeled next.

    U+003E GREATER-THAN SIGN character (>)

    Advance position to the next character in input, then jump to the next "end-of-file marker" entry below.

    End-of-file marker

    Return a start tag whose tag name is result, with no classes and no annotation, and abort these steps.

    Anything else

    Append c to result and jump to the step labeled next.

    WebVTT start tag class state

    Jump to the entry that matches the value of c:

    U+0009 CHARACTER TABULATION (tab) character
    U+000C FORM FEED (FF) character
    U+0020 SPACE character

    Append to classes an entry whose value is buffer, set buffer to the empty string, set tokenizer state to the WebVTT start tag annotation state, and jump to the step labeled next.

    U+000A LINE FEED (LF) character

    Append to classes an entry whose value is buffer, set buffer to c, set tokenizer state to the WebVTT start tag annotation state, and jump to the step labeled next.

    U+002E FULL STOP character (.)

    Append to classes an entry whose value is buffer, set buffer to the empty string, and jump to the step labeled next.

    U+003E GREATER-THAN SIGN character (>)

    Advance position to the next character in input, then jump to the next "end-of-file marker" entry below.

    End-of-file marker

    Append to classes an entry whose value is buffer, then return a start tag whose tag name is result, with the classes given in classes but no annotation, and abort these steps.

    Anything else

    Append c to buffer and jump to the step labeled next.

    WebVTT start tag annotation state

    Jump to the entry that matches the value of c:

    U+003E GREATER-THAN SIGN character (>)

    Advance position to the next character in input, then jump to the next "end-of-file marker" entry below.

    End-of-file marker

    Remove any leading or trailing space characters from buffer, and replace any sequence of one or more consecutive space characters in buffer with a single U+0020 SPACE character; then, return a start tag whose tag name is result, with the classes given in classes, and with buffer as the annotation, and abort these steps.

    Anything else

    Append c to buffer and jump to the step labeled next.

    WebVTT end tag state

    Jump to the entry that matches the value of c:

    U+003E GREATER-THAN SIGN character (>)

    Advance position to the next character in input, then jump to the next "end-of-file marker" entry below.

    End-of-file marker

    Return an end tag whose tag name is result and abort these steps.

    Anything else

    Append c to result and jump to the step labeled next.

    WebVTT timestamp tag state

    Jump to the entry that matches the value of c:

    U+003E GREATER-THAN SIGN character (>)

    Advance position to the next character in input, then jump to the next "end-of-file marker" entry below.

    End-of-file marker

    Return a timestamp tag whose tag name is result and abort these steps.

    Anything else

    Append c to result and jump to the step labeled next.

  8. Next: Advance position to the next character in input.

  9. Jump to the step labeled loop.

4.4 WebVTT cue text DOM construction rules

To convert a List of WebVTT Node Objects to a DOM tree for Document owner, user agents must create a tree of DOM nodes that is isomorphous to the tree of WebVTT Node Objects, with the following mapping of WebVTT Node Objects to DOM nodes:

WebVTT Node Object DOM node
List of WebVTT Node Objects DocumentFragment node
WebVTT Class Object HTMLElement element node with localName "span".
WebVTT Italic Object HTMLElement element node with localName "i".
WebVTT Bold Object HTMLElement element node with localName "b".
WebVTT Underline Object HTMLElement element node with localName "u".
WebVTT Ruby Object HTMLElement element node with localName "ruby".
WebVTT Ruby Text Object HTMLElement element node with localName "rt".
WebVTT Voice Object HTMLElement element node with localName "span", and a title attribute set to the WebVTT Voice Object's value.
WebVTT Class Object HTMLElement element node with localName "span", and a lang attribute set to the WebVTT Language Object's applicable language.
WebVTT Text Object Text node whose character data is the value of the WebVTT Text Object.
WebVTT Timestamp Object ProcessingInstruction node whose target is "timestamp" and whose data is a WebVTT timestamp representing the value of the WebVTT Timestamp Object, with all optional components included, with one leading zero if the hours component is less than ten, and with no leading zeros otherwise.

HTMLElement nodes created as part of the mapping described above must have their namespaceURI set to the HTML namespace, and, if the corresponding WebVTT Internal Node Object has any applicable classes, must have a class attribute set to the string obtained by concatenating all those classes, each separated from the next by a single U+0020 SPACE character.

The ownerDocument attribute of all nodes in the DOM tree must be set to the given document owner.

All characteristics of the DOM nodes that are not described above or dependent on characteristics defined above must be left at their initial values.

5. Rendering

5.1 Cues in isolation

The rules for interpreting WebVTT cue text (e.g. for use as chapter titles) are as follows:

  1. Let nodes be the List of WebVTT Node Objects obtained by applying the WebVTT cue text parsing rules to the cue's text track cue text.

  2. ...

5.2 Cues with video

5.2.1 Processing model

The rules for updating the display of WebVTT text tracks render the text tracks of a media element (specifically, a video element), or of another playback mechanism, by applying the steps below. All the text tracks that use these rules for a given media element, or other playback mechanism, are rendered together, to avoid overlapping subtitles from multiple tracks.

The output of the steps below is a set of CSS boxes that covers the rendering area of the media element or other playback mechanism, which user agents are expected to render in a manner suiting the user.

The rules are as follows:

  1. If the media element is an audio element, or is another playback mechanism with no rendering area, abort these steps. There is nothing to render.

  2. Let video be the media element or other playback mechanism.

  3. Let output be an empty list of absolutely positioned CSS block boxes.

  4. If the user agent is exposing a user interface for video, add to output one or more completely transparent positioned CSS block boxes that cover the same region as the user interface.

  5. If the last time these rules were run, the user agent was not exposing a user interface for video, but now it is, optionally let reset be true. Otherwise, let reset be false.

  6. Let tracks be the subset of video's list of text tracks that have as their rules for updating the text track rendering these rules for updating the display of WebVTT text tracks, and whose text track mode is showing.

  7. Let cues be an empty list of text track cues.

  8. For each track track in tracks, append to cues all the cues from track's list of cues that have their text track cue active flag set.

  9. If reset is false, then, for each text track cue cue in cues: if cue's text track cue display state has a set of CSS boxes, then add those boxes to output, and remove cue from cues.

  10. For each text track cue cue in cues that has not yet had corresponding CSS boxes added to output, in text track cue order, run the following substeps:

    1. Let nodes be the List of WebVTT Node Objects obtained by applying the WebVTT cue text parsing rules to the cue's text track cue text.

    2. Apply the Unicode Bidirectional Algorithm's Paragraph Level steps to the concatenation of the values of each WebVTT Text Object in nodes, in a pre-order, depth-first traversal, excluding WebVTT Ruby Text Objects and their descendants, to determine the paragraph embedding level of the first Unicode paragraph of the cue. [BIDI]

      Note

      Within a cue, paragraph boundaries are only denoted by Type B characters, such as U+000A LINE FEED (LF), U+0085 NEXT LINE (NEL), and U+2029 PARAGRAPH SEPARATOR. (This means each line of the cue is reordered as if it was a separate paragraph.)

    3. If the paragraph embedding level determined in the previous step is even (the paragraph direction is left-to-right), let direction be 'ltr', otherwise, let it be 'rtl'.

    4. If the Text track cue writing direction is horizontal, then let writing-mode be 'horizontal-tb'. Otherwise, if the Text track cue writing direction is vertical growing left, then let writing-mode be 'vertical-rl'. Otherwise, the Text track cue writing direction is vertical growing right; let writing-mode be 'vertical-lr'.

    5. Determine the value of maximum size for cue as per the appropriate rules from the following list:

      If the Text track cue writing direction is horizontal, the Text track cue alignment is start, and direction is 'ltr'
      If the Text track cue writing direction is horizontal, the Text track cue alignment is end, and direction is 'rtl'
      If the Text track cue writing direction is horizontal, and the Text track cue alignment is left
      If the Text track cue writing direction is vertical growing left, and the Text track cue alignment is start or left
      If the Text track cue writing direction is vertical growing right, and the Text track cue alignment is start or left

      Let maximum size be the text track cue text position subtracted from 100.

      If the Text track cue writing direction is horizontal, the Text track cue alignment is end, and direction is 'ltr'
      If the Text track cue writing direction is horizontal, the Text track cue alignment is start, and direction is 'rtl'
      If the Text track cue writing direction is horizontal, and the Text track cue alignment is right
      If the Text track cue writing direction is vertical growing left, and the Text track cue alignment is end or right
      If the Text track cue writing direction is vertical growing right, and the Text track cue alignment is end or right

      Let maximum size be the text track cue text position.

      If the Text track cue alignment is middle, the text track cue text position is less than or equal to 50

      Let maximum size be the text track cue text position multiplied by two.

      If the Text track cue alignment is middle, the text track cue text position is greater than 50

      Let maximum size be the result of subtracting text track cue text position from 100 and then multiplying the result by two.

    6. If the text track cue size is less than maximum size, then let size be text track cue size. Otherwise, let size be maximum size.

    7. If the Text track cue writing direction is horizontal, then let width be 'size vw' and height be 'auto'. Otherwise, let width be 'auto' and height be 'size vh'. (These are CSS values used by the next section to set CSS properties for the rendering; 'vw' and 'vh' are CSS units.) [CSSVALUES]

    8. Determine the value of x-position or y-position for cue as per the appropriate rules from the following list:

      If the Text track cue writing direction is horizontal, the Text track cue alignment is start, and direction is 'ltr'
      If the Text track cue writing direction is horizontal, the Text track cue alignment is left, and direction is 'ltr'

      Let x-position be the text track cue text position.

      If the Text track cue writing direction is horizontal, the Text track cue alignment is end, and direction is 'rtl'
      If the Text track cue writing direction is horizontal, the Text track cue alignment is left, and direction is 'rtl'

      Let x-position be the text track cue text position subtracted from 100.

      If the Text track cue writing direction is horizontal, the Text track cue alignment is end, and direction is 'ltr'
      If the Text track cue writing direction is horizontal, the Text track cue alignment is right, and direction is 'ltr'

      Let x-position be the text track cue text position minus size.

      If the Text track cue writing direction is horizontal, the Text track cue alignment is start, and direction is 'rtl'
      If the Text track cue writing direction is horizontal, the Text track cue alignment is right, and direction is 'rtl'

      Let x-position be the text track cue text position subtracted from 100, minus size.

      If the Text track cue writing direction is vertical growing left, and the Text track cue alignment is start or left
      If the Text track cue writing direction is vertical growing right, and the Text track cue alignment is start or left

      Let y-position be the text track cue text position.

      If the Text track cue writing direction is vertical growing left, and the Text track cue alignment is end or right
      If the Text track cue writing direction is vertical growing right, and the Text track cue alignment is end or right

      Let y-position be the text track cue text position minus size.

      If the Text track cue writing direction is horizontal, the Text track cue alignment is middle, and direction is 'ltr'

      Let x-position be the text track cue text position minus half of size.

      If the Text track cue writing direction is horizontal, the Text track cue alignment is middle, and direction is 'rtl'

      Let x-position be the text track cue text position subtracted from 100, minus half of size.

      If the Text track cue writing direction is vertical growing left, and the Text track cue alignment is middle
      If the Text track cue writing direction is vertical growing right, and the Text track cue alignment is middle

      Let y-position be the text track cue text position minus half of size.

    9. Determine the value of whichever of x-position or y-position is not yet calculated for cue as per the appropriate rules from the following list:

      If the Text track cue writing direction is horizontal, and the text track cue snap-to-lines flag is set

      Let y-position be zero.

      If the Text track cue writing direction is horizontal, and the text track cue snap-to-lines flag is not set

      Let y-position be the text track cue computed line position.

      If the Text track cue writing direction is vertical growing left, and the text track cue snap-to-lines flag is set
      If the Text track cue writing direction is vertical growing right, and the text track cue snap-to-lines flag is set

      Let x-position be zero.

      If the Text track cue writing direction is vertical growing left, and the text track cue snap-to-lines flag is not set
      If the Text track cue writing direction is vertical growing right, and the text track cue snap-to-lines flag is not set

      Let x-position be the text track cue computed line position.

      Note

      These are not final positions, they are merely temporary positions used to calculate box dimensions below.

    10. If the text track cue snap-to-lines flag is set, then run the appropriate steps from the following list:

      If the Text track cue writing direction is horizontal
      1. Let edge margin be a user-agent-defined horizontal length, expressed as a percentage of the width of the video's rendering area, which will be used to define a margin at the left and right edges of the video into which this cue will not be placed. In situations with overscan, this margin should be sufficient to place the cue within the title-safe area. In the absence of overscan, this value should be picked for aesthetics (to avoid text being aligned precisely on the left or right edge of the video, which can be ugly).

      2. If x-position is less than edge margin and the sum of x-position and size is more than edge margin, then increase x-position by edge margin and decrease size by the same amount.

      3. Let right margin edge be 100 minus edge margin.

      4. If x-position is less than right margin edge, and the sum of x-position and size is more than right margin edge, then decrease size by edge margin.

      If the Text track cue writing direction is vertical growing left
      If the Text track cue writing direction is vertical growing right
      1. Let edge margin be a user-agent-defined vertical length, expressed as a percentage of the height of the video's rendering area, which will be used to define a margin at the top and bottom edges of the video into which this cue will not be placed. In situations with overscan, this margin should be sufficient to place the cue within the title-safe area. In the absence of overscan, this value should be picked for aesthetics (to avoid text being aligned precisely on the top or bottom edge of the video, which can be ugly).

      2. If y-position is less than edge margin and the sum of y-position and size is more than edge margin, then increase y-position by edge margin and decrease size by the same amount.

      3. Let bottom margin edge be 100 minus edge margin.

      4. If y-position is less than bottom margin edge, and the sum of y-position and size is more than right margin edge, then decrease size by edge margin.

    11. Let left be 'x-position vw' and top be 'y-position vh'. (These again are CSS values used by the next section to set CSS properties for the rendering; 'vw' and 'vh' are CSS units.) [CSSVALUES]

    12. Apply the terms of the CSS specifications to nodes within the following constraints, thus obtaining a set of CSS boxes positioned relative to an initial containing block: [CSS]

      • The document tree is the tree of WebVTT Node Objects rooted at nodes.

      • For the purposes of processing by the CSS specification, WebVTT Internal Node Objects are equivalent to elements with the same contents.

      • For the purposes of processing by the CSS specification, WebVTT Text Objects are equivalent to Text nodes.
      • No style sheets are associated with nodes. (The nodes are subsequently restyled using style sheets after their boxes are generated, as described below.)
      • The children of the nodes must be wrapped in an anonymous box whose 'display' property has the value 'inline'. This is the WebVTT cue background box.
      • Runs of children of WebVTT Ruby Objects that are not WebVTT Ruby Text Objects must be wrapped in anonymous boxes whose 'display' property has the value 'ruby-base'. [CSSRUBY]
      • Properties on WebVTT Node Objects have their values set as defined in the next section. (That section uses some of the variables whose values were calculated earlier in this algorithm.)
      • Text runs must be wrapped according to the CSS line-wrapping rules, with the following additional constraints:
        • Regardless of the value of the 'white-space' property, lines must be wrapped at the edge of their containing blocks, even if doing so requires splitting a word where there is no line breaking opportunity. (Thus, normally text wraps as needed, but if there is a particularly long word, it does not overflow as it normally would in CSS, it is instead forcibly wrapped at the box's edge.)
        • Regardless of the value of the 'white-space' property, any line breaks inserted by the user agent for the purposes of line wrapping must be placed so as to minimize Δ across each run of consecutive lines between preserved newlines in the source. Δ for a set of lines is defined as the sum over each line of the absolute of the difference between the line's length and the mean line length of the set.
      • The viewport (and initial containing block) is video's rendering area.

      Let boxes be the boxes generated as descendants of the initial containing block, along with their positions.

    13. If there are no line boxes in boxes, skip the remainder of these substeps for cue. The cue is ignored.

    14. Adjust the positions of boxes according to the appropriate steps from the following list:

      If cue's text track cue snap-to-lines flag is set

      Many of the steps in this algorithm vary according to the Text track cue writing direction. Steps labeled "Horizontal" must be followed only when the Text track cue writing direction is horizontal, steps labeled "Vertical" must be followed when the Text track cue writing direction is either vertical growing left or vertical growing right, steps labeled "Vertical Growing Left" must be followed only when the Text track cue writing direction is vertical growing left, and steps labeled "Vertical Growing Right" must be followed only when the Text track cue writing direction is vertical growing right.

      1. Horizontal: Let margin be a user-agent-defined vertical length which will be used to define a margin at the top and bottom edges of the video into which cues will not be placed. In situations with overscan, this margin should be sufficient to place all cues within the title-safe area. In the absence of overscan, this value should be picked for aesthetics (to avoid text being aligned precisely on the bottom edge of the video, which can be ugly).

        Vertical: Let margin be a user-agent-defined horizontal length which will be used to define a margin at the left and right edges of the video into which cues will not be placed. In situations with overscan, this margin should be sufficient to place all cues within the title-safe area. In the absence of overscan, this value should be picked for aesthetics (to avoid text being aligned precisely on the left or right edges of the video, which can be ugly).

      2. Horizontal: Let full dimension be the height of video's rendering area.

        Vertical: Let full dimension be the width of video's rendering area.

        These dimensions must not be adjusted for overscan. (The algorithm does that separately.)

      3. Let max dimension be full dimension - (2 × margin).

      4. Horizontal: Let step be the height of the first line box in boxes.

        Vertical: Let step be the width of the first line box in boxes.

      5. If step is zero, then jump to the step labeled done positioning below.

      6. Let line position be the text track cue computed line position.

      7. Vertical Growing Left: Add one to line position then negate it.

      8. Let position be the result of multiplying step and line position.

      9. Vertical Growing Left: Decrease position by the width of the bounding box of the boxes in boxes, then increase position by step.

      10. If line position is less than zero then increase position by max dimension, and negate step.

        Otherwise, increase position by margin.

      11. Horizontal: Move all the boxes in boxes down by the distance given by position.

        Vertical: Move all the boxes in boxes right by the distance given by position.

      12. Remember the position of all the boxes in boxes as their specified position.

      13. Let best position be null. It will hold a position for boxes, much like specified position in the previous step.

      14. Let best position score be null.

      15. Let switched be false.

      16. Horizontal: Let title area be a box that covers all of the video's rendering area except for a height of margin at the top of the rendering area and a height of margin at the bottom of the rendering area.

        Vertical: Let title area be a box that covers all of the video's rendering area except for a width of margin at the left of the rendering area and a width of margin at the right of the rendering area.

      17. Step loop: If none of the boxes in boxes would overlap any of the boxes in output, and all of the boxes in output are entirely within the title area box, then jump to the step labeled done positioning below.

      18. Let current position score be the percentage of the area of the bounding box of the boxes in boxes that is outside the title area box.

      19. If best position is null (i.e. this is the first run through this loop, switched is still false, the boxes in boxes are at their specified position, and best position score is still null), or if current position score is a lower percentage than that in best position score, then remember the position of all the boxes in boxes as their best position, and set best position score to current position score.

      20. Horizontal: If step is negative and the top of the first line box in boxes is now above the top of the title area, or if step is positive and the bottom of the first line box in boxes is now below the bottom of the title area, jump to the step labeled switch direction.

        Vertical: If step is negative and the left edge of the first line box in boxes is now to the left of the left edge of the title area, or if step is positive and the right edge of the first line box in boxes is now to the right of the right edge of the title area, jump to the step labeled switch direction.

      21. Horizontal: Move all the boxes in boxes down by the distance given by step. (If step is negative, then this will actually result in an upwards movement of the boxes in absolute terms.)

        Vertical: Move all the boxes in boxes right by the distance given by step. (If step is negative, then this will actually result in a leftwards movement of the boxes in absolute terms.)

      22. Jump back to the step labeled step loop.

      23. Switch direction: If switched is true, then move all the boxes in boxes back to their best position, and jump to the step labeled done positioning below.

      24. Otherwise, move all the boxes in boxes back to their specified position as determined in the earlier step.

      25. Negate step.

      26. Set switched to true.

      27. Jump back to the step labeled step loop.

      If cue's text track cue snap-to-lines flag is not set
      1. Set up x and y as follows:

        If the Text track cue writing direction is horizontal, and direction is 'ltr'

        Let x be a percentage given by the text track cue text position, and let y be a percentage given by the text track cue computed line position.

        If the Text track cue writing direction is horizontal, and direction is 'rtl'

        Let x be a percentage given by the text track cue text position subtracted from 100, and let y be a percentage given by the text track cue computed line position.

        If the Text track cue writing direction is vertical growing left

        Let x be a percentage given by the text track cue computed line position subtracted from 100, and let y be a percentage given by the text track cue text position.

        If the Text track cue writing direction is vertical growing right

        Let x be a percentage given by the text track cue computed line position, and let y be a percentage given by the text track cue text position.

      2. Position the boxes in boxes such that the point x% along the width of the bounding box of the boxes in boxes is x% of the way across the width of the video's rendering area, and the point y% along the height of the bounding box of the boxes in boxes is y% of the way across the height of the video's rendering area, while maintaining the relative positions of the boxes in boxes to each other.

      3. If none of the boxes in boxes would overlap any of the boxes in output, and all the boxes in output are within the video's rendering area, then jump to the step labeled done positioning below.

      4. If there is a position to which the boxes in boxes can be moved while maintaining the relative positions of the boxes in boxes to each other such that none of the boxes in boxes would overlap any of the boxes in output, and all the boxes in output would be within the video's rendering area, then move the boxes in boxes to the closest such position to their current position, and then jump to the step labeled done positioning below. If there are multiple such positions that are equidistant from their current position, use the highest one amongst them; if there are several at that height, then use the leftmost one amongst them.

      5. Otherwise, jump to the step labeled done positioning below. (The boxes will unfortunately overlap.)

    15. Done positioning: If there are any line boxes in the (possibly now repositioned) boxes that do not completely fit inside video's rendering area, remove those offending line boxes from boxes.

    16. Let cue's text track cue display state have the CSS boxes in boxes.

    17. Add the CSS boxes in boxes to output.

  11. Return output.

User agents may allow the user to override the above algorithm's positioning of cues, e.g. by dragging them to another location on the video, or even off the video entirely.

5.2.2 Applying CSS properties to WebVTT Node Objects

When following the rules for updating the display of WebVTT text tracks, user agents must set properties of WebVTT Node Objects at the CSS user agent cascade layer as defined in this section. [CSS]

On the (root) List of WebVTT Node Objects, the 'position' property must be set to 'absolute', the 'unicode-bidi' property must be set to 'plaintext', the 'direction' property must be set to direction, the 'writing-mode' property must be set to writing-mode, the 'top' property must be set to top, the 'left' property must be set to left, the 'width' property must be set to width, and the 'height' property must be set to height, where direction, writing-mode, top, left, width, and height are the values with those names determined by the rules for updating the display of WebVTT text tracks for the text track cue from whose text the List of WebVTT Node Objects was constructed.

The 'text-align' property on the (root) List of WebVTT Node Objects must be set to the value in the second cell of the row of the table below whose first cell is the value of the corresponding cue's Text track cue alignment:

Text track cue alignment 'text-align' value
Start alignment 'start'
Middle alignment 'center'
End alignment 'end'
Left alignment 'left'
Right alignment 'right'

The 'font' shorthand property on the (root) List of WebVTT Node Objects must be set to '5vh sans-serif'. [CSSRUBY] [CSSVALUES]

The 'color' property on the (root) List of WebVTT Node Objects must be set to 'rgba(255,255,255,1)'. [CSSCOLOR]

The 'background' shorthand property on the WebVTT cue background box must be set to 'rgba(0,0,0,0.8)'. [CSSCOLOR]

A text outline or stroke may also be set on the (root) List of WebVTT Node Objects, if supported.

The 'white-space' property on the (root) List of WebVTT Node Objects must be set to 'pre-line'. [CSS]

The 'font-style' property on WebVTT Italic Objects must be set to 'italic'.

The 'font-weight' property on WebVTT Bold Objects must be set to 'bold'.

The 'text-decoration' property on WebVTT Underline Objects must be set to 'underline'.

The 'display' property on WebVTT Ruby Objects must be set to 'ruby'. [CSSRUBY]

The 'display' property on WebVTT Ruby Text Objects must be set to 'ruby-text'. [CSSRUBY]

All other non-inherited properties must be set to their initial values; inherited properties on the root List of WebVTT Node Objects must inherit their values from the media element for which the text track cue is being rendered, if any. If there is no media element (i.e. if the text track is being rendered for another media playback mechanism), then inherited properties on the root List of WebVTT Node Objects must take their initial values.

If there are style sheets that apply to the media element or other playback mechanism, then they must be interpreted as defined in the next section.

5.2.3 CSS extensions

When a user agent is rendering one or more text track cues according to the rules for updating the display of WebVTT text tracks, WebVTT Node Objects in the List of WebVTT Node Objects used in the rendering can be matched by certain pseudo-selectors as defined below. These selectors can begin or stop matching individual WebVTT Node Objects while a cue is being rendered, even in between applications of the rules for updating the display of WebVTT text tracks (which are only run when the set of active cues changes). User agents that support the pseudo-element described below must dynamically update renderings accordingly. When either 'white-space' or one of the properties corresponding to the 'font' shorthand (including 'line-height') changes value, then the text track cue's text track cue display state must be emptied and the text track's rules for updating the text track rendering must be immediately rerun.

Pseudo-elements apply to elements that are matched by selectors. For the purpose of this section, that element is the matched element. The pseudo-elements defined in the following sections affect the styling of parts of text track cues that are being rendered for the matched element.

Note

If the matched element is not a video element, the pseudo-elements defined below won't have any effect according to this specification.

A CSS user agent that implements the text tracks model must implement the '::cue' and '::cue(selector)' pseudo-elements, and the ':past' and ':future' pseudo-classes.

5.2.3.1 The '::cue' pseudo-element

The '::cue' pseudo-element (with no argument) matches any List of WebVTT Node Objects constructed for the matched element, with the exception that the properties corresponding to the 'background' shorthand must be applied to the WebVTT cue background box rather than the List of WebVTT Node Objects.

The following properties apply to the '::cue' pseudo-element with no argument; other properties set on the pseudo-element must be ignored:

  • 'color'
  • 'opacity'
  • 'visibility'
  • 'text-decoration'
  • 'text-outline'
  • 'text-shadow'
  • the properties corresponding to the 'background' shorthand
  • the properties corresponding to the 'outline' shorthand
  • the properties corresponding to the 'font' shorthand, including 'line-height'
  • 'white-space'

The '::cue(selector)' pseudo-element with an argument must have an argument that consists of a group of selectors. It matches any WebVTT Internal Node Object constructed for the matched element that also matches the given group of selectors, with the nodes being treated as follows:

The following properties apply to the '::cue()' pseudo-element with an argument:

  • 'color'
  • 'opacity'
  • 'visibility'
  • 'text-decoration'
  • 'text-outline'
  • 'text-shadow'
  • the properties corresponding to the 'background' shorthand
  • the properties corresponding to the 'outline' shorthand
  • properties relating to the transition and animation features

In addition, the following properties apply to the '::cue()' pseudo-element with an argument when the selector does not contain the ':past' and ':future' pseudo-classes:

  • the properties corresponding to the 'font' shorthand, including 'line-height'
  • 'white-space'

Properties that do not apply must be ignored.

As a special exception, the properties corresponding to the 'background' shorthand, when they would have been applied to the List of WebVTT Node Objects, must instead be applied to the WebVTT cue background box.

5.2.3.2 The ':past' and ':future' pseudo-classes

The ':past' and ':future' pseudo-classes sometimes match WebVTT Node Objects. [SELECTORS]

The ':past' pseudo-class only matches WebVTT Node Objects that are in the past.

A WebVTT Node Object c is in the past if, in a pre-order, depth-first traversal of the text track cue's List of WebVTT Node Objects, there exists a WebVTT Timestamp Object whose value is less than the current playback position of the media element that is the matched element, entirely after the WebVTT Node Object c.

The ':future' pseudo-class only matches WebVTT Node Objects that are in the future.

A WebVTT Node Object c is in the future if, in a pre-order, depth-first traversal of the text track cue's List of WebVTT Node Objects, there exists a WebVTT Timestamp Object whose value is greater than the current playback position of the media element that is the matched element, entirely before the WebVTT Node Object c.

6. WebVTT API

The following interface is used to expose WebVTT cues in the DOM API:

enum AutoKeyword { "auto" };
[Constructor(double startTime, double endTime, DOMString text)]
interface WebVTTCue : TextTrackCue {
           attribute DOMString vertical;
           attribute boolean snapToLines;
           attribute (long or AutoKeyword) line;
           attribute long position;
           attribute long size;
           attribute DOMString align;
           attribute DOMString text;
  DocumentFragment getCueAsHTML();
};
cue = new WebVTTCue( startTime, endTime, text )

Returns a new TextTrackCue object, for use with the addCue() method.

The startTime argument sets the text track cue start time.

The endTime argument sets the text track cue end time.

The text argument sets the text track cue text.

cue . vertical [ = value ]

Returns a string representing the Text track cue writing direction, as follows:

If it is horizontal

The empty string.

If it is vertical growing left

The string "rl".

If it is vertical growing right

The string "lr".

Can be set.

cue . snapToLines [ = value ]

Returns true if the text track cue snap-to-lines flag is set, false otherwise.

Can be set.

cue . line [ = value ]

Returns the text track cue line position. In the case of the value being auto, the string "auto" is returned.

Can be set.

cue . position [ = value ]

Returns the text track cue text position.

Can be set.

cue . size [ = value ]

Returns the text track cue size.

Can be set.

cue . align [ = value ]

Returns a string representing the Text track cue alignment, as follows:

If it is start alignment

The string "start".

If it is middle alignment

The string "middle".

If it is end alignment

The string "end".

If it is left alignment

The string "left".

If it is right alignment

The string "right".

Can be set.

cue . text [ = value ]

Returns the text track cue text in raw unparsed form.

Can be set.

fragment = cue . getCueAsHTML()

Returns the text track cue text as a DocumentFragment of HTML elements and other DOM nodes.

The WebVTTCue(startTime, endTime, text) constructor, when invoked, must run the following steps:

  1. Create a new text track cue. Let cue be that text track cue.

  2. Let cue's text track cue start time be the value of the startTime argument, interpreted as a time in seconds.

  3. Let cue's text track cue end time be the value of the endTime argument, interpreted as a time in seconds.

  4. Let cue's text track cue text be the value of the text argument, and let the rules for rendering the cue in isolation be the rules for interpreting WebVTT cue text.

  5. Let cue's text track cue identifier be the empty string.

  6. Let cue's text track cue pause-on-exit flag be false.

  7. Let cue's Text track cue writing direction be horizontal.

  8. Let cue's text track cue snap-to-lines flag be true.

  9. Let cue's text track cue line position be auto.

  10. Let cue's text track cue text position be 50.

  11. Let cue's text track cue size be 100.

  12. Let cue's Text track cue alignment be middle alignment.

  13. Return the TextTrackCue object representing cue.

The vertical attribute, on getting, must return the string from the second cell of the row in the table below whose first cell is the Text track cue writing direction of the text track cue that the TextTrackCue object represents:

Text track cue writing direction direction value
Horizontal "" (the empty string)
Vertical growing left "rl"
Vertical growing right "lr"

On setting, the Text track cue writing direction must be set to the value given in the first cell of the row in the table above whose second cell is a case-sensitive match for the new value, if any. If none of the values match, then the user agent must instead throw a SyntaxError exception.

The snapToLines attribute, on getting, must return true if the text track cue snap-to-lines flag of the text track cue that the TextTrackCue object represents is set; or false otherwise. On setting, the text track cue snap-to-lines flag must be set if the new value is true, and must be unset otherwise.

The line attribute, on getting, must return the text track cue line position of the text track cue that the TextTrackCue object represents. The special value auto must be represented as the string "auto". On setting, the text track cue line position must be set to the new value; if the new value is the string "auto", then it must be interpreted as the special value auto.

The position attribute, on getting, must return the text track cue text position of the text track cue that the TextTrackCue object represents. On setting, if the new value is negative or greater than 100, then an IndexSizeError exception must be thrown. Otherwise, the text track cue text position must be set to the new value.

The size attribute, on getting, must return the text track cue size of the text track cue that the TextTrackCue object represents. On setting, if the new value is negative or greater than 100, then an IndexSizeError exception must be thrown. Otherwise, the text track cue size must be set to the new value.

The align attribute, on getting, must return the string from the second cell of the row in the table below whose first cell is the Text track cue alignment of the text track cue that the TextTrackCue object represents:

Text track cue alignment align value
Start alignment "start"
Middle alignment "middle"
End alignment "end"
Left alignment "left"
Right alignment "right"

On setting, the Text track cue alignment must be set to the value given in the first cell of the row in the table above whose second cell is a case-sensitive match for the new value, if any. If none of the values match, then the user agent must instead throw a SyntaxError exception.

The text attribute, on getting, must return the raw text track cue text of the text track cue that the TextTrackCue object represents. On setting, the text track cue text must be set to the new value.

The getCueAsHTML() method must convert the text track cue text to a DocumentFragment for the script's document of the entry script by applying the WebVTT cue text DOM construction rules to the result of applying the WebVTT cue text parsing rules to the text track cue text.

7. IANA considerations

7.1 text/vtt

This registration is for community review and will be submitted to the IESG for review, approval, and registration with IANA.

Type name:
text
Subtype name:
vtt
Required parameters:
No parameters
Optional parameters:
No parameters
Encoding considerations:
8bit (always UTF-8)
Security considerations:

Text track files themselves pose no immediate risk unless sensitive information is included within the data. Implementations, however, are required to follow specific rules when processing text tracks, to ensure that certain origin-based restrictions are honored. Failure to correctly implement these rules can result in information leakage, cross-site scripting attacks, and the like.

Interoperability considerations:

Rules for processing both conforming and non-conforming content are defined in this specification.

Published specification:
This document is the relevant specification.
Applications that use this media type:
Web browsers and other video players.
Additional information:
Magic number(s):

WebVTT files all begin with one of the following byte sequences (where "EOF" means the end of the file):

  • EF BB BF 57 45 42 56 54 54 0A
  • EF BB BF 57 45 42 56 54 54 0D
  • EF BB BF 57 45 42 56 54 54 20
  • EF BB BF 57 45 42 56 54 54 09
  • EF BB BF 57 45 42 56 54 54 EOF
  • 57 45 42 56 54 54 0A
  • 57 45 42 56 54 54 0D
  • 57 45 42 56 54 54 20
  • 57 45 42 56 54 54 09
  • 57 45 42 56 54 54 EOF
Note

(An optional UTF-8 BOM, the ASCII string "WEBVTT", and finally a space, tab, line break, or the end of the file.)

File extension(s):
"vtt"
Macintosh file type code(s):
No specific Macintosh file type codes are recommended for this type.
Person & email address to contact for further information:
Silvia Pfeiffer <silviapfeiffer1@gmail.com>
Intended usage:
Common
Restrictions on usage:
No restrictions apply.
Authors:
Silvia Pfeiffer <silviapfeiffer1@gmail.com>, Ian Hickson <ian@hixie.ch>
Change controller:
W3C

Fragment identifiers have no meaning with text/vtt resources.

8. References

All references are normative unless marked "Non-normative".

[BCP47]
Tags for Identifying Languages; Matching of Language Tags, A. Phillips, M. Davis. IETF.
[BIDI]
UAX #9: Unicode Bidirectional Algorithm, M. Davis. Unicode Consortium.
[CSS]
Cascading Style Sheets Level 2 Revision 1, B. Bos, T. Çelik, I. Hickson, H. Lie. W3C.
[CSSCOLOR]
CSS Color Module Level 3, T. Çelik, C. Lilley, L. Baron. W3C.
[CSSRUBY]
CSS3 Ruby Module, R. Ishida. W3C.
[CSSVALUES]
CSS3 Values and Units, H. Lie, T. Atkins, E. Etemad. W3C.
[HTML]
HTML, I. Hickson. WHATWG.
[HTML5]
HTML 5.1, R. Berjon, T. Leithead, E. Doyle Navara, E. O'Connor, S. Pfeiffer. W3C.
[RFC3629]
UTF-8, a transformation format of ISO 10646, F. Yergeau. IETF.
[SELECTORS]
Selectors, E. Etemad, T. Çelik, D. Glazman, I. Hickson, P. Linss, J. Williams. W3C.

9. Acknowledgements

Thanks to the SubRip community, including in particular Zuggy and ai4spam, for their work on the SubRip software program whose SRT file format was used as the basis for the WebVTT text track file format.

Thanks to the many contributors to the HTML standard, where WebVTT was originally specified. [HTML], [HTML5]