HTML5 <a> Tag
ExampleA link to w3tutors.com:
Try it yourself » |
Definition and Usage
The <a> tag defines a hyperlink, which is used to link from one page to another.
The most important attribute of the a element is the href attribute, which indicates the link’s destination.
By default, links will appear as follows in all browsers:
- An unvisited link is underlined and blue
- A visited link is underlined and purple
- An active link is underlined and red
Differences Between HTML 4.01 and HTML5
In HTML 4.01, the <a> tag could be either a hyperlink or an anchor. This was determined by the href attribute. In HTML5, the <a> tag is always a hyperlink, but if it has no href attribute, it is only a placeholder for a hyperlink.
HTML5 has some new attributes, and some HTML 4.01 attributes are not supported in HTML5.
Tips and Notes
Tip: The attributes: hreflang, media, ping, rel, target, and type attributes can not be present if the href attribute is not present.
Tip: A linked page is normally displayed in the current browser window, unless you specify another target.
Tip: Use CSS to style links.
Attributes
New : New in HTML5.
Attribute | Value | Description |
---|---|---|
charset | char_encoding | Not supported in HTML5 |
coords | coordinates | Not supported in HTML5 |
href | URL | Specifies the destination of the target URL |
hreflang | language_code | Specifies the language of the target URL |
media New | media query | Specifies what media/device the target URL is optimized for. Default value: all |
name | section_name | Not supported in HTML5 |
rel | alternate archives author bookmark external first help icon index last license next nofollow noreferrer pingback prefetch prev search sidebar stylesheet tag up |
Specifies the relationship between the current document and the target URL |
rev | text | Not supported in HTML5 |
shape | default rect circle poly |
Not supported in HTML5 |
target | _blank _parent _self _top framename |
Specifies where to open the target URL |
type New | mime_type | Specifies the MIME type of the target URL |
Standard Attributes
The <a> tag also supports the Standard Attributes in HTML5.
Event Attributes
The <a> tag also supports the Event Attributes in HTML5.