- HTML Tutorial
- HTML - Home
- HTML - History and Evolution
- HTML - Overview
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Headings
- HTML - Paragraphs
- HTML - Quotations
- HTML - Comments
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Style Sheet
- HTML - CSS Classes
- HTML - CSS IDs
- HTML - Images
- HTML - Image Map
- 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 - Iframes
- HTML - Blocks
- HTML Backgrounds
- HTML - Backgrounds
- HTML Colors
- HTML - Colors
- 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 Code Builder
- HTML References
- 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
The 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. Its value will be the language code value that hints at the human language of the linked URL.
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
Following is the syntax for HTML hreflang attribute −
<a hreflang = "value"></a>
Example
In the following example, we are going to use the HTML hreflang = ‘en’ attribute within the <a> element.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML 'hreflang' attribute</title> <style> a { background-color: rgb(13, 124, 124); padding: 10px; color: white; } </style> </head> <body> <!--HTML 'hreflang' attribute--> <h3>Example of the HTML 'hreflang' attribute</h3> <p>Click on the below link to redirect to Tutorialspoint.com</p> <a href="https://www.tutorialspoint.com/index.htm" hreflang="en">Click here!</a> </body> </html>
When we run the above code, it will generate an output consisting of the text along with hyperlink applied with CSS displayed on the webpage. when we click on the link it will redirects to tutorialspoint homepsge.
Example
Considering the another scenario, where we are going to use the hreflang attribute with lan='es' along with the <a> element.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML 'hreflang' attribute</title> <style> a { text-decoration: none; background-color: rgb(12, 104, 231); padding: 10px; color: white; } </style> </head> <body> <!--HTML 'hreflang' attribute--> <h3>Example of the HTML 'hreflang' attribute</h3> <p>Click on the below button to redirect to Flamenco wikipedia</p> <a href="https://es.wikipedia.org/wiki/Flamenco" hreflang="es">Click here!</a> </body> </html>
On running the above code, the output window will pop up displaying the text along with a hyperlink on the webpage. when the user clicks on the link it redirects to wikipedia.
To Continue Learning Please Login
Login with Google