srclang

The srclang attribute specifies the language of text tracks within <track> elements, aiding accessibility for users who need subtitles or captions.

srclang attribute

The srclang attribute in HTML is employed with the <track> element to indicate the language of text tracks, such as subtitles or captions, in media elements like <video> and <audio>. This attribute aids assistive technologies, including screen readers, in recognizing the language of the track content.

Syntax

index.html
<track src="track.vtt" srclang="language-code" kind="subtitles" label="Label">

Example

index.html
<video controls>
  <source src="video.mp4" type="video/mp4">
  <track src="subtitles_en.vtt" srclang="en" kind="subtitles" label="English">
  <track src="subtitles_es.vtt" srclang="es" kind="subtitles" label="Spanish">
  Your browser does not support the video tag.
</video>
For a full list of language codes, check out our Language Code Reference.

Applicable to

The srclang attribute can be used with the following element:

ElementsAttribute
<track>srclang

Key Points

  • Language Code: The srclang attribute accepts valid language codes, such as "en" for English or "es" for Spanish.
  • Accessibility: Indicating the language for subtitles or captions improves accessibility for users who depend on these features.
  • Multiple Tracks: It's possible to add several <track> elements within a single <video> or <audio> element for various languages.

Conclusion

The srclang attribute specifies the language of subtitles or captions, improving accessibility for users relying on these features. It supports multiple language tracks within a single media element. This ensures a more inclusive experience for diverse audiences.