HTML Links

In this article, we’ll take a closer look at how HTML links work and how you can use them to create a seamless user experience on your website.

HTML links, also known as hyperlinks, are one of the most fundamental building blocks of the World Wide Web. They allow users to navigate from one web page to another by clicking on a specific piece of text or an image.

A link is a part of a webpage, and links can be found on almost every website. By clicking on links, users can navigate between pages.

A link is defined by the HTML tag <a>. Any element between the starting <a> tag and ending </a> tag becomes part of the link, which can be clicked by a user to access the linked document.

Here is a basic example of using an <a> tag. A link is defined by the HTML tag <a>.

Any element between the starting <a> tag and ending </a> tag becomes part of the link, which can be clicked by a user to access the linked document. Here is a basic example of using an <a> tag.



HTML links are hyperlinks.

A link can lead you to another document by clicking on it.

A little hand will appear when the mouse arrow is moved over a link.

It is essential to note that a link must not be text. It doesn’t matter if the link is an image or another HTML element!


In HTML, the <a> tag defines a hyperlink.

Syntax for it is as follows:

<a href=”url>Link Text</a>

href, which indicates the link’s destination, is the most important attribute of the a> element.

Readers can see the link text.

The reader will be directed to the specified URL address by clicking on the link text.

In this example, we will create a link to Mrexamples.com as follows:

Example: 

<!DOCTYPE html> <html><body><br><br><br><br><a href="https://mrexamples.com/">Visit Mrexamples.com now !!</a><br><br><br> </body></html>
  • Underlined and blue links have not been visited

  • Underlined and purple links have been visited

  • Underlined and red links are active

To get a different look at your links, you can style them with CSS.


When a link is clicked, the linked page opens in the current window of the browser. This can be changed by specifying another link target.

Linking to a document is specified by the target attribute.

One of the following values can be assigned to the target attribute:

  • _self – default. This opens the document in the same window/tab as the one in which it was clicked

  • _blank – Displays the document in a new window or tab

  • _parent – Opens the document in its parent frame

  • _top – Expands the document to fill the entire window

Use target=”_blank” if you want the linked document to appear in a new browser window or tab:

Example: 

<!DOCTYPE html> <html> <body> <a href="https://mrexamples.com/" target="_blank"> Visit Mr Examples </a> </body> </html>

Absolute URLs vs. Relative URLs

As you can see, both examples use absolute URLs (full web addresses).

A local link (which points to a page within the same website) is specified with a relative URL (rather than an absolute one).

The “https://www” part is as follows:

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

Example: 

<!DOCTYPE html> <html> <body> <h2>Absolute URLs</h2> <p> <a href="https://mrexample.com/">MRX</a> </p> <p> <a href="https://www.google.com/">Google search engine</a> </p><h2>Relative URLs</h2> <p> <a href="html_image.php">HTML Images</a> </p> <p> <a href="/css/default.php">CSS Examples</a> </p> </body> </html>

Use an image as a link in HTML

In order to use an image as a link, just place the <img> tag inside the <a> tag:

Example: 

<!DOCTYPE html> <html> <body> <a href="default.php"> <img src="https://mrexamples.com/wp-content/uploads/html_images/smiley.gif" alt="HTML example and tutorial" style="width:48px; height:48px;"> </a> </body> </html>

How to link an Email Address

Create a link using mailto: in the href attribute so users can send an email by opening their email program.

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

Example: 

<!DOCTYPE html> <html> <body> <a href="mailto:[email protected]">Send email</a> </body> </html>

How To Link Titles

Elements can be described in more detail by their title attributes.

Usually, when the mouse hovers over an element, the tooltip text displays the information.

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

Example: 

<!DOCTYPE html> <html> <body> <a href="https://mrexamples.com/html/" title="Open MrExamples HTML section">Visit our HTML Examples and Tutorial</a> </body> </html>

Adding a link to a button

You must use JavaScript code to make HTML buttons linkable.

When a button is clicked, JavaScript allows you to specify what will happen.

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

Example: 

<!DOCTYPE html> <html> <body> <button onclick="document.location='default.php'">HTML Tutorial and example</button> </body> </html>

Tip: Check out our JavaScript Tutorial for more information .


Using HTML _top

A target=\”_top\” attribute indicates the linked page or form reply will be opened in the topmost frame.

There is a full browser tab and window in the topmost frame.

Example: 

<!DOCTYPE html> <html> <head> </head> <body> <iframe width="260" height="80" style="border:2px solid #000000; padding:20px; 0 0 20px" srcdoc="<a target='_top' href='https://mrexamples.com/html/'>Mr Examples </a>"> </iframe> </body> </html>

More about relative URLs and absolute URLs

When linking to a web page, include the full URL.

Example: 

<!DOCTYPE html> <html> <body><a href="https://mrexamples.com/html/default.php">HTML example & tutorial</a></body> </html>

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

Example: 

<!DOCTYPE html> <html> <body><a href="/html/default.php">HTML Examples</a></body> </html>

Link to a web page exist in the same folder as the current page:

Example: 

<!DOCTYPE html> <html> <body> <a href="/html/default.php">HTML Examples</a> </body> </html>

Article Summary

  • Link elements are defined using the <a> element.

  • Link addresses can be defined using the href attribute.

  • Use the target attribute to define where to open the linked document.

  • Use the <img> element (inside <a>) for linking images.

  • Create a link that opens the user’s email program by using the mailto: scheme inside the href attribute.


TagOverview
<a>Defines a hyperlink

Check out our HTML Tag Reference for a full list of available HTML tags.

The following are the daily life uses of HTML links:

1.Navigation: HTML links are commonly used to create hyperlinks between different pages of a website, allowing users to navigate easily between pages.

2. Image mapping: HTML links can be used to create image maps, which allow users to click on different parts of an image to access different pages or sections of a website.

3. Email addresses: HTML links can be used to create email links that open the user’s default email client and create a new email addressed to a specific recipient.

4. File downloads: HTML links can be used to create download links that allow users to download files such as PDFs, images, or other documents.

5. Social media: HTML links can be used to create links to social media profiles or share buttons that allow users to share website content on their own social media pages.

It is requested from you to leave a reaction below in order to appreciate our efforts or to suggest improvements for this site.
We value your feedback.
+1
0
+1
0
+1
0
+1
0
+1
0
+1
0
+1
0

Subscribe To Our Newsletter
Enter your email to receive a weekly round-up of our best posts. Learn more!
icon

Leave a Reply

Your email address will not be published. Required fields are marked *