- Home
- /
- Tutorials
- /
- HTML Tutorial
- /
- HTML Links
HTML Text and Links
HTML Links
Links are what make the web a web. Every link is an a tag with an href: the address to go to. Get the href right, write link text that says where it goes, and be careful with target="_blank".
The details of the tag itself are in the a tag.
The <a> Tag – Basic Syntax
The anchor tag uses the href attribute to specify the destination URL.
Basic Example
html
<a href="https://html5andcss3.org">Visit HTML5 & CSS3</a>Types of HTML Links
a) External Links
Links to a different website.
External Links Example
html
<a href="https://www.google.com">Go to Google</a>b) Internal Links
Links to another page on the same website.
Internal Links Example
html
<a href="about.html">About Us</a>A relative address like about.html is looked up next to the current page. /about.html, starting with a slash, starts from the root of the site.
c) Anchor Links (Within Same Page)
Give the target element an id, then link to it with # and that id:
Anchor Links Example
html
<a href="#contact">Go to Contact Section</a>
<h2 id="contact" style="margin-top: 700px">Contact Us</h2>Click the link and the page jumps down to the "Contact Us" heading.
d) Email Links
Use the mailto: prefix to open an email app.
Email Link Example
html
<a href="mailto:contact@html5andcss3.org">Send Email</a>e) Phone Links
Use the tel: prefix to make a phone number clickable on mobile.
Phone Link Example
html
<a href="tel:+911234567890">Call Us</a>More on these in HTML Email Links.
The target Attribute
The target attribute defines how the link opens.
| Value | Description |
|---|---|
| _self | Opens in the same tab (default) |
| _blank | Opens in a new tab |
| _parent | Opens in the parent frame |
| _top | Opens in the full body of the window |
Link Example with Target
html
<a href="https://html5andcss3.org" target="_blank">Open in New Tab</a>When you use target="_blank" to open a link in a new tab, tell people, for example with "(opens in a new tab)", because it breaks the back button. Use it sparingly, mostly for links that would interrupt a task, like a help page in the middle of a form.
Using Links with Images
You can turn an image into a clickable link:
Image Link Example
html
<a href="https://html5andcss3.org">
<img src="/assets/images//assets/images/html5_and_css3_logo.png" alt="HTML5 Logo" width="120">
</a>The alt text of the image becomes the link's text for screen readers, so describe where the link goes, not the picture.
The title Attribute
Adds extra information that appears when you hover over the link.
Link with Title Attribute
html
<a href="https://html5andcss3.org" title="Visit HTML5 and CSS3 Tutorials">HTML5 & CSS3</a>Example: Navigation Menu Using Links
Navigation Menu Link
html
<nav>
<a href="#">Home</a> |
<a href="#">About</a> |
<a href="#">Services</a> |
<a href="#">Contact</a>
</nav>This makes a simple text menu. In a real site, replace # with the address of each page.
Writing good links
- Say where it goes. "Download the price list (PDF)" beats "Click here". Screen reader users often browse a list of links on their own, out of context.
- Make links look like links. Underlines are the clearest signal. If you remove them, use another obvious style.
- Check your links. A link to a page that has moved shows a 404 error; fix or remove it.
Browser Support
Chrome | Edge | Firefox | Safari | Opera | IE9+ |
|---|---|---|---|---|---|
| Yes | Yes | Yes | Yes | Yes | Yes |
HTML Links exercises
Build a primary navigation
Build a nav with three links: Home to /, About to /about and Contact to /contact.
Result
