HTML srclang Attribute

Beginner
4 min read
Updated: Oct 2026
3 examples
Live preview

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.

HTML Syntax

syntax.html
<track srclang=" language-tag" …>

Pair it with src (the .vtt file), kind, and usually label for the menu name.

Attribute Values

Valid BCP 47 language tags. Common examples:

ValueDescriptionTry it
enEnglishTry it
esSpanishTry it
en-US / pt-BRLanguage + regionTry it

Live Preview

Switch the subtitle language. Open the video’s captions/CC menu to confirm the track label and language.

Uses /video/count.vtt (en) and /video/count_es.vtt (es). Enable captions in the player.

Video

HTML Examples

Short study snippets. Use Try It Yourself for a live editor.

Example 1 — English Subtitles

Required srclang with kind="subtitles".

HTML
<video controls width="320" src="/video/count.mp4">
  <track kind="subtitles"
         srclang="en"
         label="English"
         src="/video/count.vtt"
         default>
</video>
Try It Yourself

How It Works

  1. track points at a WebVTT file via src.
  2. srclang="en" marks that file as English.
  3. kind="subtitles" requires a language tag.
  4. 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.

HTML
<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>
Try It Yourself

How It Works

  1. Two tracks — same kind, different srclang and files.
  2. label is the human-readable name in the CC menu.
  3. Only one default per media element.
  4. User prefs may override which language starts active.

Example 3 — Captions with Language

Captions also benefit from a clear language tag and label.

HTML
<video controls width="320" src="/video/count.mp4">
  <track kind="captions"
         srclang="en"
         label="English captions"
         src="/video/count.vtt"
         default>
</video>
Try It Yourself

How It Works

  1. kind="captions" is for dialog + relevant sound info.
  2. srclang still identifies the track language for UAs and menus.
  3. label helps users pick the right track quickly.
  4. 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.

required

Subtitles need srclang

If kind="subtitles", define srclang. Captions should still include it for clarity.

vs

srclang ≠ lang ≠ hreflang

lang = page content; hreflang = linked document; srclang = track file language.

unique

No duplicate kind + lang + label

MDN: a media element cannot have more than one track with the same kind, srclang, and label.

format

Use BCP 47 tags

Prefer en, en-US, pt-BR — not free-form strings like English.

cors

Cross-origin VTT needs CORS

Track src must be same-origin unless the parent media has a proper crossorigin setup.

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 / older
srclang Widely supported

Bottom line: Safe for modern video/audio captions. Always set srclang for subtitles and give each track a clear label.

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.

Next: srcset

Continue with responsive image candidate lists.

srcset tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

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