HTML Tags
Advertisements

HTML <a> Tag

Topic: HTML5 Tags ReferencePrev|Next

Description

The <a> (short for anchor) tag defines a hyperlink.

An anchor i.e. the <a> element can be used in two ways:

  • To create a link to another document, by using the href attribute.
  • To create a bookmark inside a document, by using the id attribute.

The following table summarizes the usages context and the version history of this tag.

Placement: Inline
Content: Inline, and text
Start/End Tag: Start tag: required, End tag: required
Version: HTML 2, 3.2, 4, 4.01, 5

In the example that follows, the <a> tag defines a link. The source anchor is the text "W3C Website" and the destination anchor is "https://www.w3.org/":

<a href="https://www.w3.org/">W3C Website</a>

This link designates the home page of the 'World Wide Web Consortium' website. When a user click on it, the web browser will retrieve the resource, in this case, an HTML document.

Note: The most important attribute of the <a> tag is the href attribute, which indicates the destination of an hyperlink.

By default, links will appear as follows in most of the browsers:

  • An unvisited link is underlined and blue.
  • A visited link is underlined and purple.
  • An active link is underlined and red.

However you can overwrite this using CSS. Learn more about styling links.


Syntax

The basic syntax of the <a> tag is given with:

HTML / XHTML: <a href="URL"> ... </a>

The example below shows the <a> tag in action.

<a href="https://www.tutorialrepublic.com/">Tutorial Republic</a>
<a href="kites.jpg"><img src="kites-thumb.jpg" alt="kites"></a>
<a href="https://www.google.com/">Google Search</a>

Tag-Specific Attributes

The following table shows the attributes that are specific to the <a> tag.

Attribute Value Description
charset charset Obsolete Specifies the character encoding of the linked resource.
coords x,y coordinates Obsolete Specifies the position of the link on the screen.
download filename Specifies whether to download the linked resource instead of navigating to it, when the user clicks on the link.
href URL Specifies the location of the destination document or web resource (such as an image, PDF, or other media file).
hreflang language-code Specifies the language of the linked document. This attribute may only be used when href is specified.
media media-query Specifies the media for which the linked resource is designed.
name text Obsolete Specifies the name of an anchor. Use the global attribute id instead.
rel alternate
author
bookmark
help
license
next
nofollow
noreferrer
prefetch
prev
search
tag
Describes the relationship between the document containing the hyperlink and the linked resource. This attribute should be used only if the href attribute is present.
rev link-type Obsolete Describes the relationship of the linked document back to the source document (the opposite of the rel attribute).
shape rect
circle
poly
default
Obsolete Specifies the shape of the hotspot region i.e. selectable region for hyperlinks.
target _blank
_parent
_self
_top
framename
Defines a target to open the linked resource specified in the href attribute.
type content-type Specifies the content type (MIME type) of the linked content–for example, "image/jpeg", "text/html" etc.

Global Attributes

Like all other HTML tags, the <a> tag supports the global attributes in HTML5.


Event Attributes

The <a> tag also supports the event attributes in HTML5.


Browser Compatibility

The <a> tag is supported in all major modern browsers.

Browsers Icon

Basic Support—

  • Firefox 1+
  • Google Chrome 1+
  • Internet Explorer 2+
  • Apple Safari 1+
  • Opera 4+

Further Reading

See tutorial on: HTML Links, CSS Links.

Related tag: <base>.

Advertisements
Bootstrap UI Design Templates Property Marvels - A Leading Real Estate Portal for Premium Properties