HTML srclang Attribute

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 3 Examples
Media & Accessibility

Introduction

The srclang attribute is an essential HTML feature associated with the <track> element. It specifies the language of a text track file—such as subtitles or captions—so browsers and media players can label tracks correctly and help users pick the language they understand.

Accurate language metadata improves accessibility for deaf and hard-of-hearing viewers (captions), non-native speakers (subtitles), and anyone using assistive technology. It is especially important for multilingual videos with several track files.

What You’ll Learn

01

<track>

Only element.

02

Language tags

en, es, fr.

03

Subtitles

Translation.

04

Captions

Accessibility.

05

label

User menu.

06

JavaScript

.srclang property.

Purpose of srclang

The primary purpose of the srclang attribute is to define the language of the track file linked by <track src>. When a video offers subtitles in English and Spanish, each <track> needs its own srclang value so the player can list “English” and “Spanish” accurately and match user language preferences where possible.

This attribute is particularly important for multimedia accessibility. Captions and subtitles are often stored as WebVTT (`.vtt`) files; srclang tells the browser what language those cues are written in, separate from the spoken audio language of the video.

💡
Pair with kind and label

srclang identifies language; kind says whether the track is subtitles, captions, descriptions, chapters, or metadata; label is the human-readable name shown in the player menu.

📝 Syntax

Add srclang on <track> inside <video> or <audio>:

srclang.html
<video controls>
  <source src="example.mp4" type="video/mp4">
  <track
    src="subtitles_en.vtt"
    kind="subtitles"
    srclang="en"
    label="English">
  <track
    src="subtitles_es.vtt"
    kind="subtitles"
    srclang="es"
    label="Spanish">
</video>

Syntax Rules

  • Valid only on <track> (child of video or audio).
  • Required when kind is subtitles or captions.
  • Value is a valid language tag (often ISO 639-1 two-letter code).
  • BCP 47 tags like en-US or pt-BR are also valid.
  • Always set label so users see a friendly name in the caption menu.
  • Use default on one track to enable it initially when supported.

💎 Values

The srclang attribute accepts language codes. Common examples:

  • srclang="en" — English.
  • srclang="es" — Spanish.
  • srclang="fr" — French.
  • srclang="de" — German.
  • srclang="ja" — Japanese.
  • srclang="en-US" — English (United States) using BCP 47.

These codes help browsers and media players identify and display the correct language for track content. Use standard tags from BCP 47 for consistency.

srclang-values.html
<track src="captions_en.vtt" kind="captions" srclang="en" label="English CC">

<track src="subtitles_fr.vtt" kind="subtitles" srclang="fr" label="Français">

⚡ Quick Reference

TopicDetailExample
Element<track> onlyInside video/audio
ValueLanguage tagen, es
Required whenkind is subtitles/captionsAlways set
Track fileWebVTT (.vtt) typicalsrc="file.vtt"
User menulabel attributelabel="English"
JavaScripttrack.srclang = "fr"Runtime update

Applicable Elements

ElementSupported?Notes
<track>YesPrimary and only use of srclang
<video>ParentContains track elements
<audio>ParentCan include tracks for captions
<source>NoUses src, not srclang
<img>, <script>NoDifferent attributes

srclang vs lang vs label

AttributeOnPurpose
srclangtrackLanguage of the .vtt track file
langAny element (global)Language of element’s text content
labeltrackDisplay name in player menu
kindtracksubtitles, captions, chapters, etc.

Examples Gallery

Multilingual subtitles, dynamic srclang updates, and accessible captions on <track>.

👀 Live Preview

A video with English and Spanish subtitle tracks identified by srclang:

Use the player’s captions/subtitles menu to switch languages.

Example — Multiple Language Tracks

Two <track> elements with different srclang values:

srclang.html
<video controls>
  <source src="example.mp4" type="video/mp4">
  <track src="subtitles_en.vtt" kind="subtitles" srclang="en" label="English">
  <track src="subtitles_es.vtt" kind="subtitles" srclang="es" label="Spanish">
</video>
Try It Yourself

How It Works

Each track points to a separate WebVTT file. srclang="en" and srclang="es" tell the player which language each file contains, so users can choose English or Spanish subtitles.

Dynamic Values with JavaScript

Update track language metadata at runtime:

dynamic-srclang.html
<track id="dynamicTrack" src="subs.vtt" kind="subtitles" srclang="en" label="Track">

<script>
  document.getElementById("dynamicTrack").srclang = "fr";
</script>
Try It Yourself

How It Works

In this script, srclang is set to fr on the track element. For full language switching you often swap the track src file or add/remove tracks rather than only changing the attribute.

Example — Captions for Accessibility

Use kind="captions" with srclang for accessible closed captions:

captions-srclang.html
<track
  src="captions_en.vtt"
  kind="captions"
  srclang="en"
  label="English captions"
  default>
Try It Yourself

How It Works

Captions differ from subtitles: they include non-speech audio cues for accessibility. srclang still identifies the written language of the caption file.

♿ Accessibility

  • Provide captions — Use kind="captions" with correct srclang for deaf and hard-of-hearing users.
  • Accurate language tags — Match srclang to the language actually used in the VTT file.
  • Clear labels — Write label text users understand (e.g. “English”, “Español”).
  • Multiple languages — Offer tracks for each supported language rather than relying on auto-translation alone.
  • Do not use captions alone for audio-only — Provide transcripts where video is not available.

🧠 How srclang Works

1

Author adds track

VTT file + srclang.

Markup
2

Browser loads cues

Parses WebVTT file.

Fetch
3

Player lists languages

label + srclang shown.

UI
=

Inclusive video

Right language track.

Browser Support

The srclang attribute on <track> is supported in all modern browsers with HTML5 video.

HTML5 · Fully supported

Text tracks in every major browser

Chrome, Firefox, Safari, and Edge support track with srclang.

98% Browser support
Google Chrome Fully supported
Full support
Mozilla Firefox Fully supported
Full support
Apple Safari Fully supported
Full support
Microsoft Edge Fully supported
Full support
srclang attribute 98% supported

Bottom line: Use srclang on every subtitles/captions track in modern HTML5 video.

💡 Best Practices

✅ Do

  • Set srclang on every subtitles and captions track
  • Use valid ISO 639-1 or BCP 47 language tags
  • Pair with descriptive label text
  • Test tracks in the browser caption menu
  • Match VTT content language to srclang

❌ Don’t

  • Omit srclang on required track kinds
  • Use made-up language codes
  • Confuse srclang with page lang
  • Label tracks incorrectly in the user menu
  • Assume one track works for all locales

Conclusion

The srclang attribute is a crucial tool for enhancing the accessibility and user experience of multimedia content in HTML. By accurately specifying the language of track files, you help users find subtitles and captions in the language they need.

Combine srclang with kind, label, and well-authored WebVTT files to build inclusive, multilingual video experiences on the web.

Key Takeaways

Knowledge Unlocked

Five truths every developer should know about srclang

Bookmark these before publishing video with tracks.

5
Core concepts
📼 02

track only

One element

Scope
📝 03

en, es, fr

Language tags

Values
⚙️ 04

.srclang JS

Dynamic update

Dynamic
05

Captions

Accessibility

A11y

❓ Frequently Asked Questions

It specifies the language of a text track file on <track>, such as subtitles or captions in WebVTT format.
Only the <track> element, used inside <video> or <audio>.
Common two-letter ISO 639-1 codes like en, es, and fr, or BCP 47 tags like en-US.
Yes when kind is subtitles or captions. Always include it for those track types.
Yes. Set track.srclang at runtime. For full language switching, update or replace track elements as needed.
Yes in all modern browsers that support HTML5 <track> elements.

Make video accessible in every language

Practice srclang on subtitle and caption tracks in the Try It editor.

Try subtitle tracks →

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.

5 people found this page helpful