HTML srclang Attribute

Definition
Definition and Usage
The srclang attribute on <track> declares the language of the timed text (WebVTT) using a BCP 47 language tag such as en or es.
Tracks sit inside <video> or <audio>. MDN: if kind is subtitles, then srclang must be defined. Not the same as global lang.
Baseline · Widely available.Not deprecated. Part of the HTML track element, widely available since about July 2015.
Required for subtitles.When kind="subtitles", omit srclang and the track is incomplete per the HTML rules.
Syntax
HTML Syntax
<track srclang=" language-tag" …>
Pair it with src (the .vtt file), kind, and usually label for the menu name.
Values
Attribute Values
Valid BCP 47 language tags. Common examples:
Try it
Live Preview
Switch the subtitle language. Open the video’s captions/CC menu to confirm the track label and language.
Code
HTML Examples
Short study snippets. Use Try It Yourself for a live editor.
Example 1 — English Subtitles
Required srclang with kind="subtitles".
<video controls width="320" src="/video/count.mp4">
<track kind="subtitles"
srclang="en"
label="English"
src="/video/count.vtt"
default>
</video>
How It Works
- track points at a WebVTT file via
src. - srclang="en" marks that file as English.
- kind="subtitles" requires a language tag.
- default turns this track on unless the user prefers another.
Example 2 — English and Spanish
One track per language so users can switch in the player menu.
<video controls width="320" src="/video/count.mp4">
<track kind="subtitles" srclang="en" label="English"
src="/video/count.vtt" default>
<track kind="subtitles" srclang="es" label="Español"
src="/video/count_es.vtt">
</video>
How It Works
- Two tracks — same kind, different
srclang and files. - label is the human-readable name in the CC menu.
- Only one default per media element.
- User prefs may override which language starts active.
Example 3 — Captions with Language
Captions also benefit from a clear language tag and label.
<video controls width="320" src="/video/count.mp4">
<track kind="captions"
srclang="en"
label="English captions"
src="/video/count.vtt"
default>
</video>
How It Works
- kind="captions" is for dialog + relevant sound info.
- srclang still identifies the track language for UAs and menus.
- label helps users pick the right track quickly.
- Same origin — VTT
src must match the page origin unless CORS is set on the media parent.
Edge Cases & Pitfalls
Language tags and track identity cause most beginner mistakes.
requiredSubtitles need srclang
If kind="subtitles", define srclang. Captions should still include it for clarity.
vssrclang ≠ lang ≠ hreflang
lang = page content; hreflang = linked document; srclang = track file language.
uniqueNo duplicate kind + lang + label
MDN: a media element cannot have more than one track with the same kind, srclang, and label.
formatUse BCP 47 tags
Prefer en, en-US, pt-BR — not free-form strings like English.
corsCross-origin VTT needs CORS
Track src must be same-origin unless the parent media has a proper crossorigin setup.
Compatibility
Browser Support
srclang is an HTML attribute on track for declaring the language of WebVTT text tracks.
✓ Baseline · Widely available
srclang
Supported wherever the HTML track element is available (widely since about July 2015).
96% Global support (approx.)
Google Chrome All modern
Full support
Mozilla Firefox All modern
Full support
Apple Safari All modern
Full support
Microsoft Edge All modern
Full support
Opera All modern
Full support
Samsung Internet Modern
Full support
Internet Explorer 10+
Partial / oldersrclang Widely supported
Bottom line: Safe for modern video/audio captions. Always set srclang for subtitles and give each track a clear label.
Remember
Key Takeaways
Role: BCP 47 language of a <track> text file.
Required: must be set when kind="subtitles".
UX: add label so users recognize the track.
Multi-lang: one track per language file.
One line: srclang tells the browser which language a subtitle/caption file is written in.
Frequently Asked Questions
On a track element, srclang declares the language of the timed text file using a BCP 47 language tag such as en or es.
The track element, nested in video or audio. It is not a global attribute like lang.
Yes when kind is subtitles. MDN: if kind is set to subtitles, then srclang must be defined.
No. lang marks the language of page content. srclang marks the language of a text track resource. hreflang is for linked resources.
Valid BCP 47 language tags, for example en, en-US, es, fr, de, ja.
Yes. Add one track per language with matching srclang and label so users can pick a track in the media menu.
About the author
Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
8 people found this page helpful