WEBVTTEvery WebVTT file must start with WEBVTT as the first line of the file, and it must occupy a single line. This is the file format identifier, used to inform the parser that this is a WebVTT format subtitle file.
WebVTT files must use UTF-8 encoding.
00:00:01.000 --> 00:00:03.000
Hello, world!Or with an identifier:
subtitle-001
00:00:01.000 --> 00:00:03.000
Hello, world!Each subtitle cue consists of the following parts:
--> or newlinesstart time --> end timeCues are separated by blank lines
Time format:
HH:MM:SS.mmm (hours:minutes:seconds.milliseconds)MM:SS.mmm (minutes:seconds.milliseconds)Minutes and seconds are required.
WEBVTT
NOTE
This is a comment.
Comments can be single line or multi-line.
NOTE
And there can be multiple comments.
Comments can also alternate with cuesNOTE: Comments, used to add author notes, will not be displayed on the screen.
Comment content can be single line or multi-line. A subtitle file can have multiple comments.
Example:
WEBVTT
00:00:32.500 --> 00:00:34.500
To grow up on these shores. To witness this water, every day
Figure 1: Subtitle without any modifications
WEBVTT
00:00:32.500 --> 00:00:34.500 size:30%
To grow up on these shores. To witness this water, every day
Figure 2: size:30% (default position:50%, align:center)
WEBVTT
00:00:32.500 --> 00:00:34.500 size:30% position:20%
To grow up on these shores. To witness this water, every day
Figure 3: size:30% position:20% (default align:center)
WEBVTT
00:00:32.500 --> 00:00:34.500 size:30% position:20% align:left
To grow up on these shores. To witness this water, every day
Figure 4: size:30% position:20% align:left
WEBVTT
00:00:32.500 --> 00:00:34.500 size:30% position:20% align:right
To grow up on these shores. To witness this water, every day
Figure 5: size:30% position:20% align:right
Optional settings can be added after the timeline, separated by spaces:
size means the percentage of screen width this box occupiesalign. The value of the align property indicates which edge of the subtitle box aligns with position.start, center (default), end, left, rightstart and end options respect the left-to-right order of the language. For right-to-left languages, such as Arabic and Hebrew, start means right side, end means left sideWEBVTT
STYLE
::cue {
color: white;
background-color: rgba(0, 0, 0, 0.8);
}
::cue(v[voice="John"]) {
color: #FFD700;
font-weight: bold;
}
::cue(.cn) {
color: #00FF88;
}The STYLE section is used to define CSS styles for subtitles and must be located after the header section and before the first subtitle cue.
Common CSS selectors:
::cue: Select all subtitle text::cue(.class): Select text with a specific class::cue(v[voice]): Select specific voice tags::cue([lang="en-US"]): Select specified language::cue-region: Select all region subtitle text::cue-region(#id): Select region subtitle text with specified idSupported CSS properties include color, font, background, text alignment, etc., but with limitations.
00:00:10.000 --> 00:00:12.000
<b>Bold text</b>
00:00:10.000 --> 00:00:12.000
<i>Italic text</i>
00:00:10.000 --> 00:00:12.000
<u>Underlined text</u>Example:
WEBVTT
00:00:32.500 --> 00:00:34.500
To <b>grow up</b> on these <u>shores</u>. To witness this water, <i>every day</i>
Text formatting tags
WebVTT supports the following text formatting tags:
<b>: Bold<i>: Italic<u>: Underline<v>: Voice tag, used to identify speakers<c>: Custom class name tag, can contain multiple class names (e.g., <c.red.bg_yellow>)<v> and <c> are discussed separately in the sections below
Example:
WEBVTT
STYLE
::cue(v[voice="Alice"]) {
color: cyan;
}
::cue(v[voice="Bob"]) {
color: yellow
}
00:00:32.500 --> 00:00:34.500
<v Alice>To grow up on these shores.</v>
<v Bob>To witness this water, every day</v>
Voice tags
The <v> tag is used to identify speakers: In the example, the speakers are named Alice and Bob. The specified speakers will not be displayed in the subtitles, but are distinguished by styles, positions, and other means. Through CSS, you can use ::cue(v[voice="Alice"]) to set styles for specific speakers.
Note: There cannot be blank lines in the
STYLEsection.
00:00:20.000 --> 00:00:22.000
<c.highlight>Important information</c>
00:00:22.500 --> 00:00:24.000
<c.cn>Chinese translation</c>
00:00:24.500 --> 00:00:26.000
Normal text <c.sound>[Sound effect]</c>Example:
WEBVTT
STYLE
::cue(c) {
color:#4E71FF;
background-color:#DDF4AA;
}
::cue(c.highlight) {
font-size:30px;
font-weight:800;
color:yellow;
background-color:green;
}
00:00:32.500 --> 00:00:34.500
<c>To grow up on these shores.</c>
<c.highlight>To witness this water, every day</c>
Text formatting tags
The <c> tag allows you to add custom class names to text fragments for CSS style control.
Syntax: <c.className>text</c>
Common use cases:
The protocol also specifies styles like <c.red.bg_yellow>, requiring players to support a set of color styles, including subtitle colors (https://w3c.github.io/webvtt/#default-text-color) and background colors (https://w3c.github.io/webvtt/#default-text-background). When using these built-in styles, subtitle authors do not need to specify STYLE.
Note: Built-in subtitle colors and background colors are well supported by players like VLC, but the browser HTML
videotag has almost no support.
WEBVTT
REGION
id:top
width:100%
lines:2
regionanchor:0%,0%
viewportanchor:0%,0%
scroll:up
REGION
id:bottom
width:100%
lines:3
regionanchor:0%,100%
viewportanchor:0%,100%Example:
WEBVTT
STYLE
::cue-region(#top) {
color: yellow;
}
REGION
id:top
viewportanchor:0%,20%
00:00:32.500 --> 00:00:34.500 region:top
To grow up on these shores. To witness this water, every day
Region anchor (Screenshot from VLC player)
REGION is used to define subtitle display regions, allowing subtitles to be displayed at different positions on the screen. By using region:regionID in the timeline settings, you can specify which region the subtitle should be displayed in.
Main properties:
region:id0%,0%)0%,100%)up means scroll up)Note: Player applications support some properties, but browsers have almost no support
The meaning of viewportanchor and regionanchor in regions. Image reference