HTML | Links
What is a link?
It is a connection from one web resource to another. A link has two ends, An anchor and direction. The link starts at the “source” anchor and points to the “destination” anchor, which may be any Web resource such as an image, a video clip, a sound bite, a program, an HTML document or an element within an HTML document. You will find many websites or social media platforms ( Like YouTube, Instagram ) which link an image to a URL or a text to a URL etc.
This basically means that by using the ‘a’ tag, you can link 1 element of the code to another element that may/may not be in your code.
HTML Link Syntax
Links are specified in HTML using the “a” tag.
href : The href attribute is used to specify the destination address of the link used. "href" stands for Hypertext reference. Text link : The text link is the visible part of the link. It is what the viewer clicks on.
An internal link is a type of hyperlink whose target or destination is a resource, such as an image or document, on the same website or domain.
Changing Link Colours in HTML
Different types of links appear in different formats such as:
- An unvisited link appears underlined and blue in colour by default.
- A visited link appears underlined and purple in colour by default.
- An active link appears underlined and red in colour by default.
The appearances of links can be changed by using CSS.
The Target Attribute in Links
The target attribute is used to specify the location where the linked document is opened. The various options that can be used in the target attribute are listed below in the table:
Using Image as a Link in HTML
An image can be used to create a link to a specified URL. When the viewer clicks on the link, it redirects them to another page.
The code is <a href=”url”>
<img src=”file address (on device or on web)” alt=”_” style=”width:__ ; height:__ ; border:__”>
Note: img src stands for image source ( i.e URL or file address )
Creating a Bookmark Link for a Webpage
A bookmark is a link that can be used to jump to specified portion of a webpage.Bookmarks are very useful if a webpage is quite long.
Steps to create a bookmark are:
1. Using the id attribute,create a bookmark.
2. Add the specified portion of the webpage to the bookmark.
Creating a download link in HTML
A text link of a pdf, doc or zip file can be created to make it downloadable.
- Google Chrome
- Microsoft Edge