HTML Links
Master HTML links to connect pages, sections, and resources. Learn external links, internal navigation, email links, and accessibility best practices.
How do you create a link in HTML?
Use the anchor element with an href: <a href="https://example.com">Visit Example</a>. The href can be an absolute URL, a path on your site (/about), a section on the page (#contact), an email (mailto:) or a phone number (tel:). Add target="_blank" to open the link in a new tab.
<a href="/tutorials/css">CSS tutorials</a>
<a href="https://developer.mozilla.org" target="_blank" rel="noopener">MDN</a>
<a href="#faq">Jump to FAQ</a>
<a href="mailto:hello@example.com">Email us</a>
<a href="/files/guide.pdf" download>Download PDF</a>The Power of HTML Links
HTML links are the foundation of web navigation, connecting pages, sections, and resources. They enable the interconnected nature of the World Wide Web and provide seamless user experiences.
Link Benefits:
- Navigation: Move between pages and sections
- SEO: Help search engines understand site structure
- Accessibility: Keyboard and screen reader friendly
- Functionality: Trigger actions and downloads
Link Anatomy
href Attribute
Specifies the URL or location the link points to. Required for functional links.
Link Text
Visible text users click on. Should be descriptive and meaningful.
Attributes
Optional attributes like target, title, and rel modify link behavior.
Types of HTML Links
1. External Links
Link to pages on different websites or domains.
Example:
<a href="https://www.google.com"
target="_blank"
rel="noopener noreferrer">
Visit Google
</a>Best Practices:
- • Use target="_blank" to open in new tab
- • Add rel="noopener noreferrer" for security
- • Include descriptive link text
- • Consider loading indicators
2. Internal Links (Anchor Links)
Navigate to different sections within the same page.
Structure:
<!-- Link to section -->
<a href="#section1">Go to Section 1</a>
<!-- Target section -->
<section id="section1">
<h2>Section 1</h2>
<p>Content here...</p>
</section>Uses:
- • Table of contents
- • "Back to top" links
- • Navigation within long pages
- • Skip to main content
3. Contact Links
Enable direct communication through email, phone, or messaging apps.
Examples:
<!-- Email link -->
<a href="mailto:info@example.com">
Send Email
</a>
<!-- Phone link -->
<a href="tel:+1234567890">
Call Us
</a>
<!-- SMS link -->
<a href="sms:+1234567890">
Send SMS
</a>Features:
- • Opens default email/phone app
- • Can include subject/body for emails
- • Works on mobile devices
- • Improves user experience
Complete Links Example
Try this comprehensive example featuring all types of HTML links with interactive styling:
Code Editor
<nav>
<a href="#about">About (same page)</a> |
<a href="https://developer.mozilla.org" target="_blank" rel="noopener">MDN (new tab)</a> |
<a href="mailto:hello@example.com">Email us</a>
</nav>
<h2 id="about">About</h2>
<p>
Read our <a href="/tutorials/html/images">guide to images</a> next.
Good link text describes where the link goes.
</p>Preview
Important Link Attributes
Essential Attributes
href=""Destination URL or anchor
target="_blank"Open in new tab/window
title=""Tooltip text on hover
Security Attributes
rel="noopener"Prevents window.opener access
rel="noreferrer"Hides referrer information
rel="nofollow"Tells search engines not to follow
Download Attributes
downloadForce download instead of navigate
download="filename.pdf"Suggest specific filename
Accessibility Attributes
aria-label=""Screen reader description
aria-describedby=""Reference to description element
Link Best Practices
Best Practices:
- Use descriptive, meaningful link text
- Add security attributes for external links
- Test links regularly for broken links
- Provide visual feedback for different link states
Common Mistakes:
- • Using "click here" or "read more" as link text
- • Opening external links without user warning
- • Not providing alternative text for image links
- • Using JavaScript for simple navigation
- • Breaking expected link behavior
- • Not testing keyboard navigation
🎯 Accessibility Guidelines:
- • Ensure links are focusable
- • Provide visible focus indicators
- • Support tab navigation
- • Use descriptive link text
- • Avoid generic phrases
- • Provide context when needed
- • Maintain color contrast
- • Don't rely only on color
- • Clear hover/active states
HTML Links — step by step
Write a basic anchor tag
The a element with an href attribute creates a link. The href value is the destination URL. The text between the tags is what users click.
🎯 Quick Check
Which rel value should you use when opening an external link with target='_blank'?
HTML Links: summary
Key points
- Use descriptive link text ("Read the CSS Grid guide"), not "click here". It helps accessibility and SEO.
- Modern browsers apply
noopenertotarget="_blank"links automatically; addingrel="noopener"is still a safe habit. - Use
<a>for navigation and<button>for actions on the same page. rel="nofollow"orrel="sponsored"tells search engines not to pass ranking credit, for example on paid links.
Frequently asked questions
›How do I open a link in a new tab?
Add target="_blank", as in <a href="…" target="_blank" rel="noopener">. Use it sparingly: users can choose to open links in new tabs themselves.
›How do I link to a section of the same page?
Give the target an id (<h2 id="faq">) and link to it with a hash: <a href="#faq">.
›What is the difference between absolute and relative URLs?
An absolute URL includes the domain (https://site.com/page). A relative URL is resolved from the current page (page.html) or the site root (/page).