0% found this document useful (0 votes)
29 views1 page

Links in HTML

Uploaded by

sepiya1758
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views1 page

Links in HTML

Uploaded by

sepiya1758
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Links in HTML: Understanding the Key Attributes

Links are a fundamental part of the web, allowing users to navigate from one page
to another. In HTML, links are created using the <a> (anchor) tag, which requires
specific attributes to define how the link behaves. In this section, we'll cover
the essential attributes of links, including href, target, and rel, and explain how
they contribute to web navigation.
1. The href Attribute

The href (hyperlink reference) attribute is the most important attribute for a
link. It defines the destination URL of the link, which can be an external website,
an internal page, or a specific section on the same page.
Example:

<a href="https://www.example.com">Visit Example</a>

In this example, when users click on the text "Visit Example", they will be
directed to https://www.example.com.

Common uses of the href attribute:

Linking to an external website:

<a href="https://www.example.com">Visit Example</a>

Linking to an internal page:

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

Linking to a specific section within the same page:

<a href="#contact">Go to Contact Section</a>

2. The target Attribute

The target attribute determines where the linked document will open. There are
several values you can use with the target attribute, including:

_blank: Opens the linked document in a new tab or window.


_self: Opens the linked document in the same tab or window (this is the default
behavior).
_parent: Opens the linked document in the parent frame (if applicable).
_top: Opens the linked document in the full browser window, removing any
frames.

Example:

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

In this example, clicking the link will open the destination website in a new tab.

Why Use `target="_blank"?

Using target="_blank" is helpful when linking to external websites or resources. It


allows users to view the new content while keeping the current page open,
preventing them from losing their place. However, it's important to use
rel="noopener noreferrer" when using target="_blank" for security reasons, which we
will cover next.

You might also like