- 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 - Text Links
A webpage can contain various links that take us directly to other web pages or resources and even specific parts of a given page.
A hyperlink is a specific type of link that allows users to navigate from one web page or resource to another by clicking on it. You can create hyperlinks using text or images available on a webpage. A hyperlink is specified using HTML tag <a>. This tag is called anchor tag and anything between the opening <a> tag and the closing </a> tag becomes part of the link and a user can click that part to reach the linked document.
We recommend you to go through a short tutorial on Understanding URL
Syntax
<a href="Document URL">Text</a>
Examples of HTML Text Links
Here are few example codes that illustrate the use of text links in HTML.
Create a hyperlink
In this example we will create a hyperlink to tutorialspoint website using anchor tag. In the output on clicking Learn tutorial you will be redirected to main page of Tutorialspoint.
<!DOCTYPE html> <html> <head> <title>Hyperlink Example</title> </head> <body> <p>Click following link</p> <a href="https://www.tutorialspoint.com/" target="_blank"> Learn Tutorials </a> </body> </html>
Target attribute of anchor Tag
The target attribute of the anchor tag in HTML specifies where to open the linked document. This attribute is used to open linked document in new browser tab, same tab or parent frame depending upon the need.
<!DOCTYPE html> <html> <head> <title>Hyperlink Example</title> <base href="https://www.tutorialspoint.com/"> </head> <body> <p>Click any of the following links</p> <a href="/html/index.htm" target="_blank"> Opens in New </a> | <a href="/html/index.htm" target="_self"> Opens in Self </a> | <a href="/html/index.htm" target="_parent"> Opens in Parent </a> | <a href="/html/index.htm" target="_top"> Opens in Body </a> </body> </html>
Use of Base Path
When you link HTML documents related to the same website, it is not required to give a complete URL for every link. You can get rid of it if you use <base> tag in your HTML document header. This tag is used to give a base path for all the links. So your browser will concatenate given relative path to this base path and will make a complete URL.
Following example makes use of <base> tag to specify base URL and later we can use relative path to all the links instead of giving complete URL for every link.
<!DOCTYPE html> <html> <head> <title>Hyperlink Example</title> <base href="https://www.tutorialspoint.com/"> </head> <body> <p>Click following link</p> <a href="/html/index.htm" target="_blank"> HTML Tutorial </a> </body> </html>
Linking to a Page Section
In the below code we demonstrate the usage of the href attribute to navigate to a different section within the same page. We provide '#idofsection' inside href to navigate section of our need.
<!DOCTYPE html> <html lang="en"> <head> <style> div { height: 900px; } </style> </head> <body> <h2>Ed-Tech</h2> <div> <p> Tutorialspoint: Simply Easy Learning </p> <a href="#about">Know More</a> </div> <h2 id="about">Section 2</h2> <div> <p> Tutorials Point is an online learning platform providing free tutorials, paid premium courses, and eBooks. Learn the latest technologies and programming languages SQL, MySQL, Python, C, C++, Java, Python, PHP, Machine Learning, data science, AI, Prompt Engineering and more. </p> </div> </body> </html>
Setting Link Text Colors
You can set colors of your links, active links and visited links using link, alink and vlink attributes of <body> tag.
Save the following in test.htm and open it in any web browser to see how link, alink and vlink attributes work.
<html> <head> <title>Hyperlink Example</title> <base href="https://www.tutorialspoint.com/"> </head> <body alink="red" link="green" vlink="black"> <p>Click following link</p> <a href="/html/index.htm" target="_blank"> HTML Tutorial </a> </body> </html>
HTML Downloadable Links
You can create text link to make your PDF, or DOC or ZIP files downloadable. This is achieved by using download attribute of anchor tag.
<!DOCTYPE html> <html> <head> <title>Hyperlink Example</title> <base href="https://www.tutorialspoint.com/"> </head> <body> <a href="/html/src/sample.txt"> View File </a> <br><br> <a href="/html/src/sample.txt" download> download File </a> </body> </html>