HTML a tag is also known as anchor tag. It defines a
hyperlink that links one page to another. The
href HTML attribute is used to give the reference(Path) of the page or document to be linked.
<a> tag is a paired tag with
</a> tag as a closing tag. Whatever is written between these two tags will feature as a hyperlink on the webpage.
The href attribute in HTML is used in a tag to give the reference(location URL) of other webpage. The full form of href is Hypertext REFerence. In simple words you just have to paste the url of the webpage in href, that you want to link.
In the example below, the text "Visit our HTML tutorial" will work as a hyperlink and will take the user to our html tutorial page. We have given the address(Path) of that page as a reference in the
target attribute is used to specify the place in the browser where the linked document should be opened. For example, whether the user wants to open the link in a new tab, new window, or in the same tag. The target attribute has different values for all these different locations.
target attribute can have one of the following values:
|target="_blank"||Opens the linked document in a new window or tab.|
|target="_self"||Opens the linked document in the same window/tab. This is the default value.|
|target="_parent"||Opens the linked document in the parent frame.|
|target="_top"||Opens the linked document in the full body of the window.|
|target="_framename"||Opens the linked document in a named frame.|
Note: HTML Frames are deprecated in HTML 5 and it is recommended not to use them.
Images can also work as a Hyperlink. It means you can add an image with a link attached to it. It is done by adding img tag within a tag. The href attribute will have the location of the linked webpage. When the user clicks on the image, he gets redirected to the attached link. It is different from the conventional linking of text with a url.
As you can see, in the example above, The
<img> tag is used within the
<a> tag. This nested structure created the whole image as a hyperlink.
When you link HTML documents related to the same website, it is not required to give a complete URL in href for every link, if you use Base Path link. This Base path is defined within
<base> tag in your HTML document header.
You can create a base path of your Base Domain. Whenever you give reference to any link, you can skip the base domain and can directly write latter part. Browser will automatically concatenate the link with the base path you have given and will make a complete URL.
Look at the example below to understand it completely.
You can set colors of your links,
active links and
visited links using link,
alink and vlink attributes of
<body> tag. However, these colors can also be given by the help of CSS classes. We will learn about it later in CSS Tutorial.