HTML <a> Tag

HTML <a> Tag

2023-09-04
2 min read

Introduction

The <a> tag in HTML creates a hyperlink to web pages, files, email addresses, locations or different URL.

href

html
<a href="https://www.google.com">Google</a>
<a href="mailto:kkan0615@gmail.com">Email</a>
<a href="tel:+1234567890">Phone</a>

The href attributes defines the URL of the page, email or phone number.

Notes

  • For the mail, it should start with mailto.
  • For the telephone, it should start with tel:
  • URL links are restricted to HTTP-based URLs.
  • Relative path indicates current URL.

hreflang

The hreflang attributes specifies the language of the link.

Notes

  • It is only used if the href attribute is set
  • language code is passed. Language codes

referrerpolicy

The referrerpolicy attribute which referrer information to send with the link

Values

  • no-referrer: The Referer header will not be sent.
  • no-referrer-when-downgrade: The Referer header will not be sent without HTTPS
  • origin: The sent referrer will be limited to the origin of the referring page: its scheme, host, and port.
  • origin-when-cross-origin: The referrer sent to other origins will be limited to the scheme, the host, and the port. Navigations on the same origin will still include the path.
  • same-origin: A referrer will be sent for same origin, but cross-origin requests will contain no referrer information.
  • strict-origin-when-cross-origin: Send a full URL when performing a same-origin request. (Default)
  • unsafe-url: The referrer will include the origin and the path. (It is unsafe)

rel

The rel describe the relationship of the link.

values

  • alternate
  • author
  • bookmark
  • external
  • help
  • license
  • next
  • nofollow
  • noreferrer
  • noopener
  • prev
  • search
  • tag

target

html
<a 
  href="https://www.google.com"
  target="_blank"
>
  Google
</a>

The target attribute defines where to display the linked URL.

values

  • _self: The current browsing context (Default)
  • _blank: Open a new tab or window.
  • _parent: The parent browsing context of the current one. If there is no parent, it behaves as _self.
  • _top: most topped browsing context. If current is top, it behaves as _self.

download

The download attribute allows to download file via link. The file name can be set or empty if you don't want to set the file name.

Ref