HTML links are created with the <a> element and its href attribute. The link text tells the user where the link leads.
<a href="https://www.plus2net.com/">Visit plus2net</a>
In this example, https://www.plus2net.com/ is the destination URL and Visit plus2net is the linked text.
<a href="destination.html">Link text</a>
The opening <a> tag starts the link and the closing </a> tag ends it.
<a href="https://www.plus2net.com/">More on plus2net</a>
href="https://www.plus2net.com/" gives the destination.More on plus2net is the visible link text.The linked text is often called anchor text. It should describe the destination or action clearly.
A relative URL points to a resource based on the location of the current document.
If test1.htm is in the same directory:
<a href="test1.htm">Go to test1.htm</a>
Relative URLs are useful for links between pages that move together as part of the same website.
../ moves one directory level up from the current document.
<a href="../test1.htm">Go to test1.htm</a>
To move up two levels and then into another directory:
<a href="../../another_dir/test1.htm">Go to test1.htm</a>
The path is resolved relative to the URL of the current page.
A URL beginning with / starts from the root of the current website.
<a href="/html_tutorial/html_form.php">HTML Form Tutorial</a>
This is different from a local disk path. The browser resolves it from the current site's origin.
An absolute URL includes the scheme and host, so it identifies the destination independently of the current page's directory.
<a href="https://www.plus2net.com/html_tutorial/html_form.php">HTML Form Tutorial</a>
Absolute URLs are commonly used when linking to another website. They can also be used for links on the same site when a fully qualified URL is needed.
The previous version of this tutorial used a Windows path such as:
H:\html_files\my_dir\test1.htm
That is a local file-system path, not a normal website URL. A web page served through HTTP or HTTPS should link with URLs such as:
<a href="/my_dir/test1.htm">Go to test1.htm</a>
or:
<a href="https://www.example.com/my_dir/test1.htm">Go to test1.htm</a>
C:\ or H:\. Those paths describe one computer's file system and are not portable web addresses.An external link uses the URL of another website:
<a href="https://www.google.com/">Visit Google</a>
The same anchor element is used for both internal and external links. The difference is the destination URL.
By default, a normal link opens in the current browsing context.
<a href="page-demo.php">Open demo</a>
If there is a genuine reason to request a new tab or window, use target="_blank":
<a
href="https://www.example.com/"
target="_blank"
rel="noopener"
>Open external site</a>
rel="noopener" prevents the opened page from using window.opener to control the source page in browsers where that relationship would otherwise exist.
Give the destination element an id:
<h2 id="installation">Installation</h2>
Then append the fragment identifier after # in the link:
<a href="targetPage.html#installation">Go to Installation</a>
The browser loads targetPage.html and attempts to move to the element whose id is installation.
<a name="targetloc"> should be replaced by an id on the actual destination element.To jump to another section of the current document, link directly to that element's id:
<a href="#faq">Go to FAQs</a>
<h2 id="faq">Frequently Asked Questions</h2>
A common example is a "Back to top" link:
<h1 id="top">Page Title</h1>
<a href="#top">Back to top</a>
See linking to different parts of the same page.
The old HTML attributes link, alink and vlink are obsolete. Link appearance should be controlled with CSS.
a {
color: #0056b3;
}
a:visited {
color: #6f42c1;
}
a:hover,
a:focus {
text-decoration: underline;
}
a:active {
color: #b02a37;
}
See styling hyperlinks with CSS.
| Attribute | Purpose |
|---|---|
href | Specifies the destination URL or fragment. |
target | Chooses the browsing context, such as _blank when a new context is intentionally requested. |
rel | Describes the relationship between the current page and the linked resource; commonly paired with certain target or external-link behaviors. |
download | Suggests downloading the linked resource instead of navigating to it, subject to browser and origin rules. |
hreflang | Indicates the language of the linked resource. |
type | Provides a hint about the MIME type of the linked resource. |
link, alink and vlink are not attributes of the <a> element. Older HTML used similarly named presentation attributes on <body>. Use CSS instead.search.htm with three links that point to Google, Yahoo and Bing. Use descriptive link text for each destination.
test1.htm, test2.htm and test3.htm. Each page should contain links to the other two pages. Use relative URLs so the three files can be moved together without rewriting every link.
For normal navigation, put the destination in the href attribute of the <a> element.
Paths such as H:\html_files\... describe one computer's file system. Use relative, root-relative or absolute web URLs.
Give the destination element an id and link to that id with #fragment.
These old presentational attributes should be replaced with CSS pseudo-classes such as :link, :visited, :hover, :focus and :active.
Prefer text that identifies the destination or purpose instead of repeating "click here" across a page.
Use normal navigation by default. Request a new browsing context only when it has a clear reason.
Use the anchor element, <a>, with an href attribute that contains the destination URL or fragment.
A relative URL is resolved from the current document or site path. An absolute URL includes the scheme and host, such as https://www.plus2net.com/.
Give the destination element an id and link to it with href="#id-value".
For modern HTML, use an id on the destination element instead.
Use CSS. Do not use obsolete link, alink or vlink presentational attributes.
It requests that the linked document open in a new browsing context, commonly a new tab. Use it only when that behavior is intentional.
No. A website served over HTTP or HTTPS should use web URLs rather than local drive-letter paths.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.