HTML DOM Link hreflang Property

HTMLWeb DevelopmentFront End Technology

The Link hreflang property sets/returns the language code of a linked document.


Following is the syntax −

  • Returning hreflang attribute value
  • Setting hreflang to a language code
linkObject.hreflang = langCode


Let us see an example for Link hreflang property −

 Live Demo

<!DOCTYPE html>
<title>Link hreflang</title>
<link id="extStyle" hreflang='en' rel="stylesheet" type="text/css" href="style.css">
<input type="button" onclick="changeStyle()" value="In what language is linked document written?">
<div id="divDisplay"></div>
   var divDisplay = document.getElementById("divDisplay");
   var extStyle = document.getElementById("extStyle");
   function changeStyle(){
      if(extStyle.hreflang === 'en'){
         divDisplay.textContent = 'The linked document is written in english';
         document.getElementsByTagName('h3')[0].textContent = 'English'

In the above example ‘style.css’ contains −

form {
   margin: 0 auto;
   text-align: center;
* {
   padding: 2px;
input[type="button"] {
   border-radius: 10px;
h3 {
   font-size: 72px;


This will produce the following output −

Before clicking ‘In what language is linked document written?’ button −

After clicking ‘In what language is linked document written?’ button −

Updated on 30-Jul-2019 22:30:26