Open In App

HTML hreflang Attribute

Improve
Improve
Like Article
Like
Save
Share
Report

HTML hreflang Attribute is used to specify the language for a linked document. It is used only when the href attribute is set. 

Syntax: 

<element hreflang="language_code"> 

Attribute Value:

The hreflang attribute contains a single value language_code which is the two-letter language code and used to specify the language of the linked document e.i. en for English, hi for Hindi etc.

HTML hreflang Attribute Supported Tags

Examples of HTML hreflang Attribute

Example 1: the This Example illustrates the use of hreflang attribute in anchor element.  

html




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML hreflang Attribute
    </title>
</head>
 
<body>
    <center>
        <h1>
            GeeksForGeeks
        </h1>
        <h2>
            HTML <a> hreflang Attribute
        </h2>
 
        <p>Welcome to
            <a href=
               id="GFG"
               rel="nofollow"
               hreflang="en-us"
               target="_self">
                GeeksforGeeks
            </a>
        </p>
    </center>
</body>
 
</html>


Output: 

HTML hreflang Attribute Example

Example 2: This Example illustrates the use of hreflang attribute in area element.  

HTML




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML area hreflang Attribute
    </title>
</head>
 
<body style="text-align:center;">
    <img src=
         alt="alt_attribute"
         width="300"
         height="119"
         class="aligncenter"
         usemap="#shapemap" />
 
    <map name="shapemap">
        <!-- area tag contained image. -->
        <area shape="poly"
              coords="59, 31, 28, 83, 91, 83"
              href=
              alt="Triangle"
              hreflang="en">
 
        <area shape="circle"
              coords="155, 56, 26"
              href=
              alt="Circle"
              hreflang="en">
 
        <area shape="rect"
              coords="224, 30, 276, 82"
              href=
              alt="Square"
              hreflang="en">
    </map>
</body>
 
</html>


Output:

HTML hreflang Attribute Example

HTML hreflang Attribute Example Output

Supported Browsers:

The browser supported by hreflang Attribute are listed below:  



Last Updated : 08 Mar, 2024
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads