Home > Abakada: Back to Basics > Language References > HTML Elements > A Element
Defines the destination of a hypertext link. | HTML 2, 3.2, 4, 4.01, 5 |
HTML Syntax
<a
download = filename
href = url
hreflang = language_code
ping = url_list
referrerpolicy = no-referrer | no-referrer-when-downgrade | origin | origin-when-cross-origin |
same-origin | strict-origin-when-cross-origin | unsafe-url
rel = alternate | author | bookmark | external | help | license | next | nofollow | noreferrer |
noopener | prev | search | tag
target = _blank | _parent | _self | _top | window_name
type = media_type
>
NOTE: Both start and end tags are required.
The A element is commonly used to:
- link to another hypertext document, or
- link to a specific location within the same, or another, hypertext document
The A element requires either the:
- href attribute when used as a hypertext link, to specify the link’s destination URI.
- id attribute when used as an anchor, to identify the anchor’s location within a document.
Both text and images can be included within an <a
> element used as a hyperlink.
The <a
> element is not restricted to HTTP-based URLs. It can also use the following URL schemes supported by most browsers.
- Telephone numbers with
tel:
URLs
- Email addresses with
mailto:
URLs
- SMS text messages with
sms:
URLs
- Executable code with javascript: URLs
Browsers typically render textual hyperlinks with a different color and an underline, though authors may use CSS styles to override this default behavior.
The <a>
element supports the following attributes, in addition to global attributes common to all HTML elements.
download | filename | Causes the browser to treat the linked URL as a download. |
href | URL | Specifies the URL that the hyperlink points to. |
hreflang | language_code | Specifies the language of the linked document. |
media | media_query | Specifies what media/device the linked document is optimized for |
ping | url_list | Specifies a space-separated list of URLs, typically used for tracking. |
referrerpolicy | no-referrer, no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin-when-cross-origin, unsafe-url | Specifies which referrer information to send with the link. |
rel | alternate, author, bookmark, external, help, license, next, nofollow, noreferrer, noopener, prev, search, tag | Specifies the relationship between the current document and the linked document. |
target | _blank, _parent, _self, _top | Specifies where to open the linked document. |
type | media_type | Specifies the media type of the linked document |
Following are several examples of using the <a
> element.
Linking to an absolute path:
<a href="https://asp.net.ph">Home</a>
Specifying a named location that can be used as the destination of other links:
<h3><a id="atts">Attributes</a></h3>
Linking to a location within the same document:
<a href="#atts">Attributes</a>
Specifying the target window or frame to load the linked resource:
<a href="somewhere.com" target="travel">Destinations</a>
Using an image as a hyperlink:
<a href="somewhere.com"><img src="home.png"></a>
Calling a JavaScript function compliant with the ECMA-262 language specification ( ex. opens a new window ):
<a href="javascript:window.open ( )">Show me</a>
LINK Anchors and Links