HTML links are the hyperlinks i.e. links are those text/ buttons by which we can go to another page/website by clicking on it.
We can also use images as a link.
Links are written using <a> tag and has href as its attribute. Users can click on anything between the opening <a> tag and the closing <a> tag.
The value of this attribute is the address of the website that is reached when the user clicks on hyperlinked text.
- When you link to a different website, the value of the href attribute will be the full web address for the site, which is known as an absolute URL.
- When you are linking to other pages within the same site, you do not need to specify the domain name in the URL. You can use shorthand known as a relative URL.
- If all the pages of the site are in the same folder, then the value of the href attribute is just the name of the file.
- When linking to the same page ‘#’ value is used.
Links can be made more attractive by using CSS or by using style attribute such as color, background color, hover properties, text transform etc.
HTML link colors:
By default, a link will appear like this:
- An unvisited link is underlined and blue.
- A visited link is underlined and purple.
- An active link is underlined and red.
We can change the default colors by using CSS.
The target attribute:
It specifies where to open the linked document. The target attribute can have one of the following values:
- _blank – opens the linked document in new window or tab
- _self – opens the linked document in the same window or tab as it was clicked.
- _top – opens the linked document in the full body of the window.
- _parent – opens the linked document in the parent frame.