Understanding HTML Link Best Practices
Well-designed HTML links help visitors understand where they can go, what will happen when a link is selected, and how different pages and resources are connected throughout a website.
Good link practices combine meaningful link text, appropriate URL types, accessibility, predictable behavior, and regular testing to create navigation that works well for both visitors and search engines.
Use Descriptive Link Text
Link text should describe the destination or action clearly enough that visitors can understand the purpose of the link before selecting it.
<!-- Avoid vague link text -->
<a href="contact.html">Click Here</a>
<!-- Better -->
<a href="contact.html">Contact Us</a>
Descriptive link text is especially helpful for visitors using screen readers because links may be encountered separately from the surrounding paragraph. It also makes pages easier to scan visually.
Choose the Appropriate URL Type
Use the URL type that best matches the destination. Relative and root-relative URLs are commonly used for resources within the same website, while absolute URLs are generally used when linking to another website.
<!-- Relative URL -->
<a href="contact.html">Contact</a>
<!-- Root-relative URL -->
<a href="/about/company.html">About Our Company</a>
<!-- Absolute URL -->
<a href="https://www.example-web.site">Example Website</a>
Using a consistent URL strategy makes links easier to maintain and reduces unnecessary path errors as a website grows.
Keep Links Recognizable
Visitors should be able to distinguish links from surrounding text without having to search for them. Browsers traditionally display links with an underline and a different text color, although websites often customize their appearance with CSS.
Links should remain visually distinguishable from ordinary text even when their default browser styling is changed. Do not rely on subtle differences that make interactive text difficult to recognize.
Keep Link Behavior Predictable
A normal link should take the visitor to the destination indicated by its text. Avoid using links to trigger unexpected actions or sending visitors somewhere unrelated to what the link describes.
When a link performs a special action, such as downloading a file, opening an email message, or starting a telephone call, its text should make that purpose clear whenever the action may not otherwise be obvious.
Opening Links in New Windows
The target attribute can be used with _blank to request that a link open in a new browsing context.
<a href="https://www.example-web.site" target="_blank">Visit Example Website</a>
Opening new windows or tabs should be used selectively because it changes normal browser navigation and can be unexpected for visitors. When opening a new browsing context is important to the experience, consider making that behavior clear to the visitor.
Special-Purpose Links
Some links perform actions other than navigating to the top of another webpage. The link should use the appropriate URL scheme or HTML attribute for the intended action.
<!-- Email -->
<a href="mailto:name@example-web.site">Email Us</a>
<!-- Telephone -->
<a href="tel:+12027621401">202-762-1401</a>
<!-- Page fragment -->
<a href="#contact">Jump to Contact Information</a>
<!-- Download -->
<a href="guide.pdf" download>Download the HTML Guide</a>
Choosing the correct type of link helps browsers and devices perform the intended action and makes the link's purpose easier for visitors to understand.
Create Accessible Links
Links should be usable with a mouse, keyboard, touchscreen, and assistive technologies. Native <a> elements with valid href values provide built-in keyboard and accessibility behavior that should be preserved.
Use meaningful link text, maintain a visible keyboard focus indicator, provide sufficient visual contrast, and avoid removing useful browser behaviors without providing an accessible alternative.
Avoid Broken Links
A broken link sends visitors to a resource that cannot be found or reached. Broken links can result from renamed or deleted files, incorrect paths, changed external URLs, or mistakes in the href value.
Test links before publishing and periodically check important links after a site is online. Internal links are especially easy to maintain when filenames, directories, and URL conventions are kept consistent.
HTML Link Best Practices Example
The following example demonstrates several links whose text clearly communicates their different destinations and actions.
<nav aria-label="Helpful links">
<ul>
<li><a href="about.html">About Us</a></li>
<li><a href="#contact">Contact Information</a></li>
<li><a href="mailto:name@example-web.site">Email Us</a></li>
<li><a href="tel:+12027621401">Call the Time and Date Service</a></li>
<li><a href="guide.pdf" download>Download HTML Guide (PDF)</a></li>
</ul>
</nav>
Each link communicates what the visitor can expect before it is selected. The telephone example also uses the working time and date service number used in the Telephone Links tutorial.
Link Best Practices Checklist
- Write descriptive link text that identifies the destination or action.
- Choose an appropriate relative, root-relative, or absolute URL.
- Keep links visually distinguishable from ordinary text.
- Maintain visible keyboard focus styles.
- Use new windows or tabs selectively.
- Identify downloads and other special link actions clearly.
- Use appropriate
mailto:andtel:schemes for email and telephone links. - Use unique and stable
idvalues for fragment-link destinations. - Check internal and external links for broken destinations.
- Test important links with different browsers and devices when practical.
Summary
Effective HTML links use descriptive text, appropriate URLs, recognizable styling, accessible behavior, and reliable destinations. Following consistent link practices makes a website easier to navigate, easier to maintain, and more predictable for visitors using different browsers, devices, and assistive technologies.
