![HTML Tutorial](/html/images/html-mini-logo.jpg)
- HTML Tutorial
- HTML - Home
- HTML - Introduction
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Headings
- HTML - Paragraphs
- HTML - Fonts
- HTML - Blocks
- HTML - Style Sheet
- HTML - Formatting
- HTML - Quotations
- HTML - Comments
- HTML - Colors
- HTML - Images
- HTML - Image Map
- HTML - Iframes
- HTML - Phrase Elements
- HTML - Meta Tags
- HTML - Classes
- HTML - IDs
- HTML - Backgrounds
- HTML Tables
- HTML - Tables
- HTML - Headers & Caption
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML Color Names & Values
- HTML - Color Names
- HTML - RGB
- HTML - HEX
- HTML - HSL
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Picker
- HTML References
- HTML - Cheat Sheet
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - hreflang Attribute
HTML hreflang attribute is used to specify the language of the linked document or URL.
It works only when the href attribute is specified otherwise not. The HTML hreflang tag is used to tell search engines about the different versions of the same page in different languages. This helps search engines to serve the correct version of the page to their users based on their language preference.
Syntax
<a hreflang = "value"></a>
Where value is two letter code of language.
Applies On
Below listed elements allow using of the HTML hreflang attribute
Element | Description |
---|---|
<a> | HTML <a> tag is used to attach external resource using links to webpage. |
<link> | HTML <link> tag specifies relationship between the current document and an external resource. |
<area> | HTML <area> tag specifies the areas of the image, mapping that can be clicked on or are active areas that are linked to by hyperlinks. |
Examples of HTML hreflang Attribute
Below examples will illustrate the HTML href attribute, where and how we should use this attribute!
Using hreflang to Specify English Language
In the following example, we are going to use the HTML hreflang = ‘en’ attribute within the <a> element to specify language of hyperlink provided is English.
<!DOCTYPE html> <html lang="en"> <body> <h3>Example of HTML 'hreflang' attribute</h3> <p> Below link will redirect you to Tutorialspoint </p> <a href="/index.htm" hreflang="en"> Click here! </a> </body> </html>
hreflang attribute to specify language of stylesheet
Considering the another scenario, where we are going to use the hreflang attribute with link tag to specify language of CSS stylesheet as English.
<!DOCTYPE html> <html lang="en"> <head> <title>Example of hreflang Attribute</title> <link rel="alternate" hreflang="en" href="styles.css" /> </head> </html>style.css
* { margin: 0; padding: 0; border: 0 solid transparent; } html { -webkit-text-size-adjust: 100%; } body { min-height: 100vh; line-height: 1; text-rendering: optimizeSpeed; }
Hreflang attribute inside area tag
In this example we use hreflang attribute inside area map, where we redirect according to the part of image clicked. Here all the values of hreflang is English(en) since all the website we redirect is also in English.
<!DOCTYPE html> <html lang="en"> <body> <h1>Welcome to our interactive map!</h1> <p> Click on a region to visit the respective language page: </p> <img src="/html/images/lang.jpg" usemap="#langmap" alt="World Map" /> <map name="langmap"> <area shape="rect" coords="0,0,180,165" alt="HTML" href="html/index.htm" target="_blank" hreflang="en" /> <area shape="rect" coords="180,0,375,167" alt="JavaScript" href="javascript/index.htm" target="_blank" hreflang="en" /> <area shape="rect" coords="0,166,180,338" alt="PHP" href="/php/index.htm" target="_blank" hreflang="en" /> <area shape="rect" coords="180,165,375,338" alt="ReactJS" href="reactjs/index.htm" target="_blank" hreflang="en" /> </map> </body> </html>
Supported Browsers
Attribute | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
hreflang | Yes | Yes | Yes | Yes | Yes |