<a>

The HTML <a> element defines hyperlinks, enabling navigation to external webpages, resources, or sections within the same document, using attributes like href, target, and rel.

a tag

The HTML <a> tag (anchor tag) is a fundamental element for creating hyperlinks. It enables text or images to become clickable, directing users to external sites, internal sections, or downloadable files. The href attribute specifies the destination, while attributes like target control how the link opens.

Syntax

index.html
<a href="...">Content...</a>
index.html
<a href="https://institute.qarpeo.com">
  <img border="0" alt="Qarpeo" src="logo_w3s.gif" width="100" height="100">
</a>
index.html
<a href="https://institute.qarpeo.com" target="_blank">Visit https://institute.qarpeo.com</a>

Linking to an email address

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

Linking to a phone number

index.html
<a href="tel:+4733378901">+47 333 78 901</a>
index.html
<a href="#section2">Go to Section 2</a>
index.html
<a href="javascript:alert('Hello World!');">Execute JavaScript</a>
If the <a> tag lacks an href attribute, it serves as a placeholder for a hyperlink.

Overview and Function

The <a> element enables navigation within or outside a webpage. Its key attribute, href, determines the link destination.

  • Default styles for links in most browsers:
  • Unvisited links appear blue and underlined.
  • Visited links appear purple and underlined.
  • Active links (when clicked) appear red and underlined.
If an <a> element lacks an href attribute, it does not function as a hyperlink but can still be styled and used in scripts.

Attributes

AttributeValueDescription
downloadfilenameEnables file downloads when the link is clicked.
hrefURLSpecifies the hyperlink's destination.
hreflanglanguage_codeIndicates the language of the linked resource.
mediamedia_queryDefines the media type or conditions for the link.
pinglist_of_URLsSends a request to listed URLs when the link is clicked, typically for tracking.
referrerpolicyno-referrer
no-referrer-when-downgrade
origin
origin-when-cross-origin
same-origin
strict-origin-when-cross-origin
unsafe-url
Controls referrer information sent with link requests.
relalternate
author
bookmark
external
help
license
next
nofollow
noreferrer
noopener
prev
search
tag
Defines the relationship between the current and linked pages.
target_blank
_parent
_self
_top
Specifies how the linked page will open.
typemedia_typeSpecifies the content type of the linked document.

See also

Explore additional elements related to text formatting:

<abbr> <em> <strong> <small> <cite> <q> <dfn> <time> <code> <var> <samp> <kbd> <sup> <b> <i> <mark> <ruby> <rp> <rt> <bdo> <span> <br> <wbr>.

Conclusion

The <a> tag is an essential HTML element for navigation. With attributes like href, target, and download, it enables linking to web pages, downloadable resources, and interactive actions such as phone calls and JavaScript execution. This makes it a key tool for structuring content and user interactions on the web.