The Tutorial SIte

Menu
  • Bootstrap 4
  • CSS
  • HTML
Home
HTML
HTML Links – A Guide
HTML

HTML Links – A Guide

HTML links are essential for navigation on the web.

They allow users to move between webpages, sections within a page, files, and external websites. Links are created using the <a> (anchor) tag.

This tutorial will cover:

  1. Basic Syntax of HTML Links
  2. Types of Links
  3. Link Attributes (href, target, title, download, rel)
  4. Opening Links in a New Tab
  5. Creating Email and Phone Links
  6. Using Links for Navigation (Internal Links)
  7. Linking to an External Website
  8. Styling Links with CSS
  9. Making Buttons as Links
  10. Best Practices for Using Links

1. Basic Syntax of HTML Links

The basic syntax for a hyperlink uses the <a> tag with the href attribute.

Example: Basic Link

<a href="https://example.com">Visit Example</a>
  • The href attribute defines the link’s destination.
  • The text inside the <a> tag (Visit Example) is clickable.

Output:

Visit Example

2. Types of Links

HTML supports different types of links:

  1. External Links – Link to another website.
  2. Internal Links – Navigate within the same website.
  3. Anchor Links – Jump to a specific section of a page.
  4. Email Links – Open the user’s email client.
  5. Phone Links – Initiate a phone call.
  6. Download Links – Provide file downloads.

3. Link Attributes

1. href (Hyperlink Reference)

The href attribute specifies the URL or file path.

Example:

<a href="https://www.wikipedia.org">Visit Wikipedia</a>

2. target (Open in New Tab or Window)

The target attribute defines where the link will open.

Value Behavior
_self Default (opens in the same tab)
_blank Opens in a new tab
_parent Opens in the parent frame (used in frames)
_top Opens in the full browser window, breaking frames

Example:

<a href="https://example.com" target="_blank">Open in New Tab</a>

3. title (Tooltip Text)

Displays a tooltip when hovering over a link.

Example:

<a href="https://example.com" title="Click to visit Example">Example</a>

4. rel (Relationship)

Defines the relationship between the current page and the linked page.

Value Purpose
nofollow Tells search engines not to follow the link
noopener Prevents security risks when opening in a new tab
noreferrer Prevents sending referrer information

Example:

<a href="https://example.com" target="_blank" rel="noopener noreferrer">Secure Link</a>

5. download (Download Files)

Forces a file to download instead of opening it in the browser.

Example:

<a href="document.pdf" download>Download PDF</a>

4. Opening Links in a New Tab

To open a link in a new tab, use:

<a href="https://example.com" target="_blank">Open in New Tab</a>

For security, always add:

rel="noopener noreferrer"

This prevents security vulnerabilities when opening a new tab.

5. Creating Email and Phone Links

1. Email Links (mailto)

An email link opens the default email client.

Example:

<a href="mailto:contact@example.com">Send Email</a>
  • Can include a predefined subject:
<a href="mailto:contact@example.com?subject=Hello">Email Us</a>

2. Phone Links (tel)

A phone link opens the dialer on mobile devices.

Example:

<a href="tel:+1234567890">Call Us</a>

6. Using Links for Navigation (Internal Links)

Internal links connect pages within the same website.

Example:

<a href="about.html">About Us</a>

7. Linking to an External Website

Links to external websites must include absolute URLs.

Example:

<a href="https://www.google.com">Visit Google</a>

8. Styling Links with CSS

HTML links can be styled using CSS pseudo-classes.

a {
    color: blue;
    text-decoration: none; /* Removes underline */
}

a:hover {
    color: red; /* Changes color on hover */
}

a:visited {
    color: purple; /* Changes color after being clicked */
}

a:active {
    color: orange; /* Changes color when clicked */
}

Example: Styled Link

<a href="https://example.com">Styled Link</a>
  • hover – Changes color when the user hovers.
  • visited – Changes color after visiting.
  • active – Changes color while clicking.

9. Making Buttons as Links

Sometimes, links need to look like buttons.

Example: Button Link (CSS Styled)

<a href="https://example.com" class="button">Click Me</a>
.button {
    display: inline-block;
    background-color: blue;
    color: white;
    padding: 10px 20px;
    text-decoration: none;
    border-radius: 5px;
}

.button:hover {
    background-color: darkblue;
}

This makes a clickable button that acts as a link.

10. Best Practices for Using Links

1. Use Descriptive Anchor Text

Bad Example:

<a href="https://example.com">Click here</a>

Good Example:

<a href="https://example.com">Visit Our Website</a>

Why?

  • SEO-friendly (descriptive text improves rankings).
  • Better accessibility.

2. Avoid Broken Links

Always check links to ensure they work.

3. Use nofollow for Untrusted Links

When linking to external, untrusted sites, use:

<a href="https://example.com" rel="nofollow">External Site</a>

4. Secure External Links

When opening links in a new tab, add:

rel="noopener noreferrer"

to prevent security risks.

5. Avoid Excessive Links

Too many links reduce readability. Keep navigation clear and concise.

 

Conclusion

  • Use the <a> tag with the href attribute.
  • Use absolute URLs for external links and relative URLs for internal links.
  • Open links in a new tab using target=”_blank” with rel=”noopener noreferrer”.
  • Use mailto: for email links and tel: for phone links.
  • Style links with CSS for a better user experience.
  • Use descriptive text for SEO and accessibility.
Share
Telegram
Linkedin
Pocket
Pinterest
Tweet
Email
Prev Article
Next Article

Related Articles

HTML Quotations – A Guide
HTML provides several elements to format quotations and citations, making …

HTML Quotations – A Guide

HTML Paragraphs – A Guide
HTML paragraphs help structure text content on a webpage. The …

HTML Paragraphs – A Guide

Categories

  • Bootstrap 4
  • CSS
  • HTML

Latest

  • HTML Classes : A Tutorial
  • HTML Tables : A Tutorial
  • HTML iframe : A Tutorial
  • HTML div : A Detailed Tutorial
  • Bootstrap 4 Tutorial Collection
  • CSS Tutorial Collection
  • HTML Tutorial Collection
  • HTML head : A Detailed Tutorial
  • Popular
  • Recent
  • Tags

The Tutorial SIte

Copyright © 2025 The Tutorial SIte
The Tutorial Site

Ad Blocker Detected

Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by disabling your ad blocker.

Refresh