HTML <a> Tag
The HTML <a> tag also known as the HTML anchor tag is used to specify a hyperlink to link one page to another. The hyperlink can be created to another web page or a file, a location, or a URL. To link to the destination page or URL, the “href” attribute is used with the HTML anchor tag.
Syntax:
<a href = "..........."> Link Text </a>
The href attribute:
To define the address of the file to be linked or to point out at the destination page, the href attribute of the HTML anchor tag is used. Attributes like download, hreflang, media, rel, target, and type can be used only if the href attribute is present.
Example:
<!DOCTYPE html> <html> <body> <p>Visit our Website for more info:</p> <a href="https://www.w3schools.blog">w3schools.com</a> </body> </html>
Explanation:
In the above example, one can check the use of the HTML anchor tag as well as the use of the href attribute of the HTML anchor tag.
Using target attribute:
The link of a page, when clicked, displays the page in the current browser window. To open a link to another page the target attribute of the HTML anchor tag is used. Otherwise, the link will open on the same page. This attribute of the HTML anchor tag can only be used with the href attribute of the HTML anchor tag.
Example:
<!DOCTYPE html> <html> <body> <p>Visit our Website for more info:</p> <a href="https://www.w3schools.blog" target="_blank" rel="noopener">w3schools.com</a> </body> </html>
Explanation:
In the above example, we are using the target attribute of the HTML anchor tag to open the link to the next page.
The appearance of HTML anchor tag:
- Unvisited link: Underlined and blue.
- Visited link: Underlined and purple.
- Active link: Underlined and red.
Supporting Browsers:
Chrome, IE, Firefox, Opera, and Safari.