The HTML <a> Tag and Its Attributes

The <a> tag defines a hyperlink, which is used when linking from one page to another. This is used with the href attribute, which defines the link’s destination. If an <a> tag has no href attribute then it will only be a placeholder for a hyperlink. There are other attributes which are used alongside the <a> tag and the href attribute.

The HTML <a> Tag and Its Attributes


The href attribute specifies the URL where the page link will go to. Without this then the <a> tag will not be a hyperlink, which is why it is the most important attribute of the <a> tag.  It would be set out like this <a href”(URL of the link)”> (then the text you want the URL to be linked to) </a>.


The download attribute allows the file to be downloaded when the link is clicked on, rather than navigating to the file. The href attribute is used again, which specifies the file that will be downloaded when the hyperlink is clicked. Another attribute that can be used alongside this is filename, which specifies the new filename for the file being downloaded. There are no restrictions on the allowed values, and the browser will automatically detect the correct file extension and add it to the file. If a filename is not specified then the original name will be used.


The media attribute specifies what media/device the linked document is optimised for. The target URL will be designed for special devices such as iphones, or for speech synthesisers or print media. This attribute can accept several values, so if you want to use multiple devices. For example, if you have separate stylesheets for different devices so you would use the media attribute to specify the device type. It is also used with the href attribute to specify a URL, or it will not work.


This attribute specifies a list of URLs to be notified if a user clicks on the link. A HTTP POST request will be sent to the specified URL. This request contains the string which is sent. Using the ping attribute allows information to be sent about links that are clicked without having to write custom javascript code. This is also useful for bringing transparency which is a way of tracking, which is used for search engine optimisation. Bots and users will know what links are being tracked so this is better than using a tracking link.


The referrer policy attribute specifies which information to send when a hyperlink is clicked. To set the referrer policy for a link it can be done like this <a href=”(URL)” referrer policy=”origin”> The ‘origin’ is an attribute used which sends the origin information of the document. There are other attributes that can be used with the referrer policy attribute.


The rel attribute will specify the relationship between the current document, and the linked document. It is again used with the href attribute otherwise it will not work. The type of the relationship is given by the rel attribute which will have a value that is a unique set of keywords. The keywords have to be unique within that value. Search engines may also use information from the rel attribute to determine how to index or display the page.


The target attribute will specify where to open the linked document. The <a tag will determine the link to open, and target= will specify where it opens. Users will set the target to have a specific value. ‘_blank’ will open the link in a new window or tab, ‘_self’ opens the link in the same frame as it was clicked (which is default), ‘_parent’ will open the link in the parent frame and ‘_top’ will open it in the full body of the window. ‘Framename’ can also be used to open it in the named iframe.