Open In App

How to specify the language of the document in a given link in HTML5 ?

Last Updated : 06 Jun, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

In the HTML5 language of the document, a given link is specified by hreflang attribute. The value (or languageCode) passed here is the code of the website language. (e.g., if the document/website in the given link is in English en is passed as the value).

Example 1: Below is the example that illustrates the use of the hreflang attribute.

HTML
<!DOCTYPE html>
<html>

<body>
    <h2>Welcome To GFG</h2>
    <p>Click
        <a href="https://www.geeksforgeeks.org/" hreflang="en">
            here
        </a>to visit GeeksForGeeks website
    </p>
</body>
</html>

Output: Upon clicking on the above link it will redirect to the following document which is in English: 

Example 2: In this example, we will use hreflang for the Spanish language.

HTML
<!DOCTYPE html>
<html>
  
<body>
    <h2>Welcome To GFG</h2>
    <p>Click
        <a href=
"https://es.wikipedia.org/wiki/Idioma_espa%C3%B1ol" 
           hreflang="es">
            here
        </a>
        to visit Wikipedia spanish website
    </p>
</body>
</html>

Output:  Upon clicking on the above link it will redirect to the following document which is in Spanish:


Next Article

Similar Reads