srclang
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
<track src="track.vtt" srclang="language-code" kind="subtitles" label="Label">
Example
<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>
Applicable to
The srclang
attribute can be used with the following element:
Elements | Attribute |
---|---|
<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.
srcdoc
The srcdoc attribute allows you to embed HTML content directly within an <iframe>, specifying the content to display instead of an external source.
srcset
The srcset attribute provides multiple image sources for the <img> element, allowing browsers to choose the most appropriate image based on display conditions.