HTML Links – Hyperlinks
Hyperlinks are one of the most exciting innovations the Web has to offer. It allow us to link documents to other documents or resources, link to specific parts of documents, or make apps available at a web address.
We can create links in HTML if we use anchor elements. The anchor tags are these
</a>tags. A link does not have to be text. A link can be an image or any other HTML element.
<a href="url">Some Text</a>
The following about one attribute that will tell the browser how to open the link we have clicked. This attribute name is called
<a href="url" target="_blank">With Target Attribute</a>
The target attribute will tell the browser where to open the linked document.
_blank– It will tell the browser to open the link in a new window or tab.
_self– It will open the linked document in the same frame as it was clicked or this is the default action of the anchor tag.
_top– It will open the linked document in the full body of the window
_parent– It will open the linked document in the parent frame
Link to an Email Address
mailto: inside the href attribute to create a link that opens the user’s email program.
<a href="mailto:firstname.lastname@example.org">Send email</a>
Use an Image as a Link
To use an image as a link, just put the
<img> tag inside the
<a href="url"> <img src="/2.png" alt="CJ" /> </a>
Download an Image
If we want to download a file from a server using the anchor tag.We have attribute called
download and it does not require a value.
<a href="2.png" download>Download</a>
Absolute URLs and Relative URLs
- Absolute URLs – A link with
- Relative URLs – A local link (a link to a page within the same website) is specified with a relative URL
<a href="https://codejagd.com/html-links">HTML Links</a>
codejagd.com– Site Name
html-links– File Name
<a href="/html-links">HTML Links</a>