a: The Anchor element
The <a>
HTML element (or anchor element), with its href
attribute, creates a hyperlink to web pages, files, email addresses, locations in the same page, or anything else a URL can address.
Content within each <a>
should indicate the link’s destination. If the href attribute is present, pressing the enter key while focused on the <a>
element will activate it.
Attributes
Specific attributes
Recommended attributes
href="[URL]"
the URL that the hyperlink points to. Links are not restricted to HTTP-based URLs — they can use any URL scheme supported by browsers:
- Sections of a page with document fragments
- Specific text portions with text fragments
- Pieces of media files with media fragments
- Telephone numbers with
tel:
URLs - Email addresses with
mailto:
URLs - SMS text messages with
sms:
URLs
Allowed attributes
download="[filename]"
causes the browser to treat the linked URL as a download. Can be used with or without a filename value. The filename will be proposed to save the file locally.
hreflang="[lang]"
hints at the human language of the linked URL. Allowed values are defined by RFC 5646
rel="[relationship]"
specifies the relationship between the current document and the linked document.
target="[target value]"
Where to display the linked URL, as the name for a browsing context (a tab, window). The following keywords have special meanings for where to load the URL:
- _self: The current browsing context. (Default)
- _blank: Usually a new tab, but users can configure browsers to open a new window instead.
- parent: The parent browsing context of the current one. If no parent, behaves as self.
- top: The topmost browsing context. To be specific, this means the “highest” context that’s an ancestor of the current one. If no ancestors, behaves as self.
- _unfencedTop: Allows embedded fenced frames to navigate the top-level frame (i.e. traversing beyond the root of the fenced frame, unlike other reserved destinations). Note that the navigation will still succeed if this is used outside of a fenced frame context, but it will not act like a reserved keyword.
type="[mime type]"
Hints at the linked URL’s format with a MIME type.
Global attributes
accesskey
Specifies a keyboard shortcut to activate or focus an element.
aria-*
Defines accessibility properties and states for assistive technologies.
class
Specifies one or more CSS class names for styling the element.
data-*
Stores custom data private to the page or application.
dir
Sets the text direction (left-to-right, right-to-left, or auto).
hidden
Hides the element from display and assistive technologies.
id
Defines a unique identifier for the element within the document.
inputmode
Hints which virtual keyboard type to display on mobile devices.
itemid
Provides a global identifier for microdata items.
itemprop
Defines a property name-value pair for microdata.
itemref
Associates properties with an item via element IDs for microdata.
itemscope
Creates a new microdata item container.
itemtype
Specifies the vocabulary URL for microdata items (like Schema.org).
lang
Specifies the primary language of the element’s content.
nonce
Provides a cryptographic nonce for Content Security Policy.
role
Defines the element’s semantic role for accessibility.
tabindex
Controls keyboard navigation order and focusability.
title
Provides advisory information displayed as a tooltip.
Example
<a href="https://smolweb.org" target="_blank" referrerpolicy="origin">SmolWeb</a>