a – link
<a href="url">link text</a>
A link – to another page, to a place on the page (#anchor), to an email address (mailto:), a phone number (tel:) or a file to download. Only an element with the href attribute is a link; without it, it is a placeholder that cannot be clicked or reached with the Tab key.
- Default display:
display: inline - End tag: required
- Content: anything its parent may contain (even blocks), but without interactive elements (another link, a button, a form field)
- Where it can be used: anywhere phrasing content is allowed; it may also wrap a block
- DOM interface:
HTMLAnchorElement
Attributes
- href – the target of the link: a URL (
/contact/,https://…), an anchor (#method= the element withid="method"),mailto:info@example.com,tel:+15551234567. - target – where the target opens:
_blank(a new window or tab),_self(default),_parent,_topor the name of a frame. - rel – the relationship to the target:
noopenerandnoreferrer(security and privacy), for search enginesnofollow,sponsored(a paid link) andugc(a link from users). - download – downloads the file instead of opening it; the value is the suggested file name. It works only for URLs from the same website.
- hreflang, type – the language and type of the target page (information only).
- referrerpolicy – which URL of the page the browser sends to the target.
Examples
A link to a page, to a place on the page, an email and a phone number:
<p> <a href="/contact/">Contact</a> · <a href="#opening-hours">Opening hours</a> · <a href="mailto:info@example.com">info@example.com</a> · <a href="tel:+15551234567">555 123 4567</a> </p>
A link to another website in a new window, a paid link and a file to download:
<a href="https://www.example.org/" target="_blank" rel="noopener">Partner (opens in a new window)</a> <a href="https://www.example.net/offer/" rel="sponsored">Advert</a> <a href="/files/price-list-2026.pdf" download="price-list.pdf">Price list (PDF, 120 kB)</a>
A whole card as one link – a link may wrap blocks too:
<a class="card" href="#bread"> <h3>Sourdough bread</h3> <p>From our own starter, €4.50</p> </a>
.card {
display: block;
max-width: 240px;
padding: 4px 12px;
border: 1px solid #ccc;
border-radius: 8px;
color: inherit;
text-decoration: none;
}
Accessibility
The text of a link should say where it leads even out of context – screen readers can list all links on a page and “click here” says nothing in that list. It is good to mention in the text that a link opens in a new window. A link goes somewhere, a button (button) does something – “Send” or “Close” should not be a link with href="#".
Things to watch out for
- Browsers today treat
target="_blank"as if it hadrel="noopener"– the new page does not get access to the original one viawindow.opener(Chrome since 88, Firefox since 79, Safari since 12.1, as of October 2026). For older browsersrel="noopener"is still written. - A link must not contain another link or a button. The browser pulls a nested link out of the outer one and the page falls apart.
- Without
hrefthe browser does not give the element the look of a link (color, underline) and it cannot be reached with the keyboard. - Browsers ignore
downloadfor a file from another website and just open the file. - Check URLs from visitors (comments, profiles) –
href="javascript:…"runs a script (XSS).
Browser support
Baseline – widely available: works in all major browsers and has for a long time (since 2015 at the latest). Since version: Chrome 1, Firefox 1, Safari 1. As of October 2026 (MDN browser-compat-data).
Related:
button – button
base – base URL
area – image map area
nav – navigation
id – identifier (attribute)
title – element tooltip (attribute)