HTML Links: The a Element, href and target Explained
Links are what make the web a web. The <a> element (for "anchor") turns its content into a link, and its href attribute says where the link goes. Without href, an <a> is just a placeholder and is not clickable.
Kinds of URLs
- Absolute URLs include the scheme and domain:
https://www.sqlite.org/docs.html. Use them for other sites. - Root-relative URLs start with
/and are resolved against the current site:/files/guide.pdf. - Relative URLs like
about.htmlor../index.htmlare resolved against the current page's folder. - Fragment links start with
#and jump to the element with thatidon the page, likehref="#contact". Combine both, as in/python/lists/#common-mistakes, to jump to a section of another page.
Expected page text
Links Visit the SQLite documentation. Python docs in a new tab Jump to the contact section Email us or call. Download the guide Contact Back to top
Opening in a new tab
target="_blank" opens the link in a new tab or window. Use it sparingly; most people prefer to decide that themselves. Modern browsers treat _blank links as if rel="noopener" were set, which stops the new page from controlling the original one through window.opener. Adding rel="noopener" explicitly keeps older browsers safe too.
Special schemes and download
mailto: links open the visitor's email program, and tel: links start a call on phones. The download attribute asks the browser to save the linked file instead of navigating to it; it only works for files on the same site.
Writing good link text
The text inside the link should make sense on its own, because screen-reader users often browse a list of all links on a page. "SQLite documentation" is useful; "click here" or "read more" is not. Search engines also use link text to understand the page being linked to.
Links can wrap almost any content, including images and whole blocks such as a card with a heading and summary. They cannot contain other links or interactive elements such as buttons.
Common mistakes
- Forgetting the
https://in external links, which turns them into relative links on your own site. - Using
<a>withouthrefand a click handler as a fake button. Use<button>for actions and<a href>for navigation. - Link text like "here" that gives no hint of the destination.
Summary
<a href="...">creates a link; the content is what users click.- URLs can be absolute, root-relative, relative or
#fragment. target="_blank"opens a new tab; pair it withrel="noopener".- Write link text that describes the destination.
Quiz: Links