A cue is one piece of text with a start and end time, and settings that place it on the screen.
One cue
| Line | Content | Notes |
|---|---|---|
| Identifier | any text without --> | Optional. Unique in the file. CSS can select a cue by it, as ::cue(#id). |
| Timing line | start --> end, then optional settings | Spaces or tabs, at least one, around --> and between settings. |
| Text | one or more lines | See Cue text. Ends at the first blank line. |
The start must be later than or equal to the start of every earlier cue, and the end later than the start. Cues may overlap.
Timestamps
A timestamp is hh:mm:ss.ttt or, when the hours are zero, may be
mm:ss.ttt.
| Part | Digits | Range |
|---|---|---|
Hours and : | 2 or more | 0 and up; optional when 0 |
| Minutes | exactly 2 | 00–59 |
| Seconds | exactly 2 | 00–59 |
. and milliseconds | exactly 3 | 000–999 |
The full stop before the milliseconds is the quickest way to tell WebVTT from SRT, which uses a comma.
Cue settings
Each setting is name:value, at most once per cue, in any order. A
setting with no colon, or a colon at either end, is skipped, as is any value a player
does not recognise.
| Setting | Values | Default | Meaning |
|---|---|---|---|
vertical | rl, lr | horizontal | Vertical text, with lines growing right to left or left to right. |
line | a line number (may be negative), or a percentage; then optionally ,start, ,center or ,end | auto, start | Where the cue sits across the lines of the video: a line number counts lines from the top (or from the bottom when negative); a percentage is a distance across the video. The alignment says which edge of the cue box goes there. |
position | a percentage, 0 to 100; then optionally ,line-left, ,center or ,line-right | auto, auto | Where the cue box sits along the line, as a percentage of the video’s width (or height, for vertical text). |
size | a percentage, 0 to 100 | 100% | The width of the cue box (height for vertical text), at most the maximum size that the position allows. |
align | start, center, end, left, right | center | How the text lines are aligned inside the box. start and end follow the text direction. |
region | a region id | none | Shows the cue in a region. |
A percentage is digits, optionally with a decimal part, then %, such as
12.5%. A cue loses its region if it also has vertical, a
line other than auto, or a size other than
100%.
How a parser reads the timing line and settings
W3C WebVTT section 6.3. The rule that a setting appears at most once is for authors; a parser accepts anything and is forgiving:
- The timing line is read as: skip white space, a timestamp, white space,
-->, white space, a timestamp, then the settings. If any of that fails, the whole cue block is discarded (it is not shown and its text is not treated as another block). White space around-->may be any amount. - A setting name or value is any run of characters other than a line feed or carriage
return, and the whole name or value must not contain
-->. - The rest of the line is split on spaces into settings. A token with no colon, or
whose first colon is its first or last character, is skipped; the setting names and the
keywords (
rl,lr,start,center,end,line-left,line-right,left,right) are matched case-sensitively. - Every percentage (
position,sizeand alineending in%) must match the percentage syntax and be between 0 and 100, or that setting is skipped and the earlier or default value stays. linewithout a percent sign may have a decimal part:line:1.5,line:-2. It must contain at least one digit; a minus sign is allowed only as the first character; there may be at most one full stop, with a digit on each side. A comma may be followed bystart,centerorend; any other alignment word skips the whole setting, so the line value is not applied either.position’s alignment word is likewiseline-left,centerorline-right, and any other word skips the setting.- A repeated setting is not an error: each is processed in turn, so the last valid
one wins.
region:picks the last region defined earlier in the file with that identifier, or no region if there is none. - Settings are applied in the order written, and the rules that remove the region
apply as they go:
vertical:rlorvertical:lr, alineother thanauto, and asizeother than 100 each set the cue’s region to none at the moment that setting is read, andregion:sets it again whenever it is read. As written in the algorithm, aregion:written before such a setting is therefore lost, and one written after it takes effect.
How the position is worked out
| Value | When auto or left out |
|---|---|
| Line | A line number: the cue goes on the last line (−1) if its track is the first track showing, −2 for the second, and so on. Players then stack overlapping cues line by line. A line given as a percentage turns this snapping to lines off. In a file the parser always sets a numeric line when snapping is off, because it turns snapping off only when it reads a percentage line. (The specification’s computed-line algorithm returns 100 for an auto line with snapping off, a state reachable only through the script interface’s snapToLines and line attributes, not from a file.) |
| Position | 0 for align:left, 100 for align:right, otherwise 50. |
| Position alignment | line-left for align:left; line-right for align:right; for start, line-left in left-to-right text and line-right otherwise; for end the reverse; otherwise center. |
| Alignment | Edge of the cue box placed at the value |
|---|---|
Line start | Top (horizontal text); left for vertical:lr; right for vertical:rl |
Line center | The middle |
Line end | Bottom; right for vertical:lr; left for vertical:rl |
Position line-left | Left (horizontal text) or top (vertical) |
Position center | The middle |
Position line-right | Right (horizontal text) or bottom (vertical) |
Effective size of the cue box
The rendering steps (W3C WebVTT, “Processing cue settings”) compute a maximum size
from the computed position and the position alignment, and the box uses the smaller of
the cue’s size and that maximum:
| Position alignment | Maximum size |
|---|---|
line-left | 100 minus the computed position |
line-right | the computed position |
center, position 50 or less | the computed position times two |
center, position over 50 | (100 minus the computed position) times two |
So position:80%,line-left size:100% gives a box 20% wide, and
position:30% size:80% (centre alignment) gives 60%.
Line numbers, offsets and direction
From the W3C WebVTT definitions of a cue’s line, position, size and text alignment and the note on the line cue setting.
- Line numbers. A
linewithout a percent sign is in units of the size of the first line of the cue. Positive numbers count from the start of the video viewport, the first line being numbered 0; negative numbers count from the end, the last line being −1. A number with a decimal part is rounded when the cue is laid out on lines: the rendering steps add 0.5 and then round down, soline:1.5is line 2 andline:-1.5is line −1. - Which edge the line offsets from. The line setting offsets the cue
box in the direction across the lines: for horizontal text from the top edge of the
video; for
vertical:rl(lines growing left) from the right edge; forvertical:lr(lines growing right) from the left edge. The offset is of the start, centre or end of the box, as the line alignment says (start by default). A line given as a percentage is of the height of the video for horizontal text and of its width for vertical text. - Position percentages. A
positionis of the width of the video for horizontal text and of its height for vertical text; inside a region it is of the region’s dimension. For horizontal cues with right-to-left text the box is still positioned from the left edge of the video. - Size, alignment and automatic position. The automatic position
is 50% for
start,centerandendalignment (0% forleft, 100% forright). Authors must therefore not leavepositionautomatic for a cue whosesizeis not 100% and whose alignment isstartorend: the automatic position would not follow the text direction, which can differ from line to line. - Base direction of a line. The base direction of each text line, used
by the Unicode bidirectional algorithm, is found from the first strong directional
character of that line (the CSS
unicode-bidi: plaintextalgorithm). To correct a wrong result, start the line with U+200E LEFT-TO-RIGHT MARK or U+200F RIGHT-TO-LEFT MARK (written‎or‏).
Worked example
00:00:04.000 --> 00:00:06.250 line:10%,start position:25%,line-left size:50% align:start
Somewhere we have never been.