HTML Links - SwatiMaurya08/html-notes GitHub Wiki
A link 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 to the linked document. Following is the simple syntax to use <a>
tag.
<a href = "Document URL" ... attributes-list>Link Text</a>
This attribute is used to specify the location where linked document is opened. Following are the possible options −
- _blank
Opens the linked document in a new window or tab.
- _self
Opens the linked document in the same frame.
- _parent
Opens the linked document in the parent frame.
- _top
Opens the linked document in the full body of the window.
- targetframe
Opens the linked document in a named targetframe.
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.
You can set colors of your links, active links and visited links using link, alink and vlink attributes of <body>
tag.
You can create text link to make your PDF, or DOC or ZIP files downloadable. This is very simple; you just need to give complete URL of the downloadable file.
It's simple to use an image as hyperlink. We just need to use an image inside hyperlink at the place of text.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Image Hyperlink Example</title>
</head>
<body>
<p>Click following link</p>
<a href = "https://www.tutorialspoint.com" target = "_self">
<img src = "/images/logo.png" alt = "Tutorials Point" border = "0"/>
</a>
</body>
</html>
HTML <a>
tag provides you option to specify an email address to send an email. While using tag as an email tag, you will use mailto: email address along with href attribute. Following is the syntax of using mailto instead of using http.
<a href = "mailto: [email protected]">Send Email</a>
You can specify a default email subject and email body along with your email address. Following is the example to use default subject and body.
<a href = "mailto:[email protected]?subject = Feedback&body = Message">
Send Feedback