Links are found on nearly all website pages. Links allow users to click their way from one page to another.

What is a link?

It is a connection from one Web resource to another. A link has two ends, An anchor and direction. The connection begins at the “source” anchor and points to the “destination” anchor, which might be any Web resource like a picture, a video clip, a sound bite, a program, an HTML document, or an element inside an HTML document.


HTML Links – Hyperlinks

HTML links are hyperlinks.

You can tap on a link and leap to another document.

At the point when you move the mouse over a link, the mouse arrow will turn into a little hand.

Note: A link doesn’t need to be text. A link can be a picture or some other HTML element!


HTML Links – Syntax

The HTML <a> tag defines a hyperlink. It has the accompanying syntax:

<a href="url">link text</a>

The main attribute of the <a> element is the href attribute, which demonstrates the link’s destination.

The link text is the part that will be visible to the reader.

Tapping on the link text, will send the reader to the specified URL address.

Example

This example shows the best way to create a link to worldofitech.com:

<a href="https://www.worldofitech.com/">Visit worldofitech.com!</a>

Output

Visit worldofitech.com!

By default, links will show up as continues in all browsers:

  • An unvisited link is underlined and blue
  • A visited link is underlined and purple
  • A active link is underlined and red

Tip: Links can obviously be styled with CSS, to get another look!


HTML Links – The target Attribute

By default, the linked page will be shown in the current browser window. To change this, you should determine another target for the link.

The target attribute indicates where to open the linked document.

The target attribute can have one of the accompanying values:

  • _self – Default. Opens the document in a similar window/tab as it was clicked
  • _blank – Opens the document in another window or tab
  • _parent – Opens the document in the parent frame
  • _top – Opens the document in the full body of the window

Example
Use target=”_blank” to open the linked document in a new browser window or tab:

<a href="https://www.worldofitech.com/" target="_blank">Visit worldofitech!</a>

Absolute URLs vs. Relative URLs

The two examples above are using an outright URL (a full web address) in the href attribute.

A local link (a link to a page inside a similar site) is indicated with a relative URL (without the “https://www” part):

Example

<h2>Absolute URLs</h2>
<p><a href="https://www.w3.org/">W3C</a></p>
<p><a href="https://www.google.com/">Google</a></p>

<h2>Relative URLs</h2>
<p><a href="html_images.asp">HTML Images</a></p>
<p><a href="/css/default.asp">CSS Tutorial</a></p>

HTML Links – Use an Image as a Link

To use a picture as a link, just put the <img> tag inside the <a> tag:

Example

<a href="default.asp">
<img src="smiley.gif" alt="HTML tutorial" style="width:42px;height:42px;">
</a>

Link to an Email Address

Use mailto: inside the href attribute to create a link that opens the user’s email program (to allow them to send another email):

Example

<a href="mailto:[email protected]">Send email</a>

Button as a Link

To use an HTML button as a link, you need to add some JavaScript code.

JavaScript allows you to determine what occurs at specific occasions, like a tick of a catch:

Example

<button onclick="document.location='default.html'">HTML Tutorial</button>

Link Titles

The title attribute determines additional data about an element. The data is regularly appeared as a tooltip text when the mouse moves over the element.

Example

<a href="https://www.worldofitech.com/html/" title="Go to worldofitech HTML section">Visit our HTML Tutorial</a>

Output

Visit our HTML Tutorial

More on Absolute URLs and Relative URLs

Example
Use a full URL to link to a web page:

<a href="https://www.worldofitech.com/html">HTML tutorial</a>

Example
Link to a page located in the html folder on the current web site:

<a href="/html/default.html">HTML tutorial</a>

Example
Link to a page located in the same folder as the current page:

<a href="default.html">HTML tutorial</a>

Chapter Summary

  • Use the <a> element to define a link
  • Use the href attribute to define the link address
  • Use the target attribute to define where to open the linked document
  • Use the <img> element (inside <a>) to use an image as a link
  • Use the mailto: conspire inside the href attribute to create a link that opens the user’s email program

HTML Link Tags
Tag         Description
<a>        Defines a hyperlink

Thanks for reading! We hope you found this tutorial helpful and we would love to hear your feedback in the Comments section below. And show us what you’ve learned by sharing your photos and creative projects with us.


0 Comments

Leave a Reply

Avatar placeholder