About WebVTT subtitles files
The subtitle format for <track> in HTML video. Browsers ignore a track served with any other type, with no visible error. Files must start with WEBVTT; SubRip (.srt) subtitles look similar but use commas in timestamps and need converting first.
File signature
VTT files start with "WEBVTT" (after an optional BOM). The extension and the type a browser reports for an upload both
come from the file name, so check these bytes on the server before trusting a file.
Serve .vtt with the right Content-Type
Content-Type: text/vtt; charset=utf-8
text/vtt vtt;
AddType text/vtt .vtt
AddCharset UTF-8 .vtt
@vtt path *.vtt
header @vtt Content-Type "text/vtt; charset=utf-8"
curl -sI https://example.com/file.vtt | grep -i '^content-type'
# Content-Type: text/vtt; charset=utf-8
Set the type in code
res.set('Content-Type', 'text/vtt; charset=utf-8');
import mimetypes
mimetypes.add_type('text/vtt', '.vtt') # if your system doesn't know it
mimetypes.guess_type('file.vtt')[0] # 'text/vtt'
mime.AddExtensionType(".vtt", "text/vtt; charset=utf-8")
w.Header().Set("Content-Type", "text/vtt; charset=utf-8")
Accept .vtt uploads
<input type="file" accept=".vtt,text/vtt">
The accept attribute only filters the file picker; users can still choose another file. Listing the
extension as well as the type matters, because operating systems don’t always report the type you expect.
Related types
-
.mp4 (
video/mp4): MP4 video -
.webm (
video/webm): WebM video -
.m3u8 (
application/vnd.apple.mpegurl): HLS playlist
More web
.html , .css , .js , .mjs , .svg , .wasm , .webmanifest , .rss . Look up any extension or type with the MIME type lookup.
Sources
Spotted a mistake? Email hello@devtoolsmith.com and we’ll fix it.
Frequently asked questions
What is the MIME type for .vtt files?
text/vtt. It is a text format, so add the character set: "Content-Type: text/vtt; charset=utf-8".
Why does my server send the wrong Content-Type for .vtt?
Web servers pick the type from the file extension using a table (mime.types in nginx and Apache). If .vtt is missing from that table, they send a default such as application/octet-stream or text/plain. Add the mapping as shown on this page, then check the response with "curl -sI".
How can I check that a file really is VTT?
Look at the first bytes rather than the extension or the type the browser reports, which both come from the file name. VTT files start with "WEBVTT" (after an optional BOM). The MIME type lookup on this site reads them for you when you drop a file on it.