Open In App

HTML srclang Attribute

Last Updated : 29 Aug, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The srclang attribute is used to specify the language of the track text. The srclang attribute can be applied on the <track> element:
Note: srclang attribute is required with kind = “subtitles”.

Syntax

<track src="subtitles_en.vtt" kind="subtitles" srclang="en">

Example: Below is an example of srclang attribute

html
<html>

<head>
</head>

<body style="text-align: center">
    <h1 style="color: green">
        GeeksforGeeks
    </h1>
    <h2>HTML srclang Attribute</h2>

    <video width="100" height="100" controls>

        <track src=
"https://write.geeksforgeeks.org/wp-content/uploads/11.mp4" 
               id="myTrack1" 
               kind="subtitles"
               srclang="en" label="English">

        <source id="myTrack" src=
"https://write.geeksforgeeks.org/wp-content/uploads/11.mp4" type="video/mp4">
    </video>


    <p>
        Click the button to get
        the language of the track.
    </p>


    <button onclick="myFunction()">
        Get srclang
    </button>

    <p id="gfg"></p>

    <!-- Script to get the 
      value of srclang property -->
    <script>
        function myFunction() {
            let x =
                document.getElementById("myTrack1");

            document.getElementById(
                "gfg").innerHTML = x.srclang;
        }
    </script>
</body>

</html>

Output: Click the button to get the value of srclang attribute: 
 

Supported Browsers: 


Next Article

Similar Reads