The title attribute in an anchor tag serves multiple important purposes for both usability and accessibility. The primary purpose is to provide additional information about the link that appears as a tooltip when users hover their mouse over the link. This tooltip helps users understand where the link leads before clicking it. For example, a link with text download might have a title attribute explaining download product brochure, PDF, 2 megabytes. This gives users context about what they are downloading. The title attribute is particularly useful in several scenarios. First, when link text is necessarily brief or generic, the title can provide more detail. Second, for external links, the title can indicate that the link opens an external site. Third, for download links, the title can specify the file type and size. Fourth, for links with icons only, the title provides a text description. From an accessibility perspective, the title attribute is announced by screen readers, helping visually impaired users understand link purposes. However, you should not rely solely on title attributes for critical information because they have limitations. Title tooltips only appear on hover, so they are not accessible on touch devices like phones and tablets. They also have inconsistent browser support and styling. Some users may not discover them. Best practices include making the link text itself descriptive enough to stand alone. Use the title attribute to provide supplementary information, not essential information. Keep title text concise but informative. Avoid redundant titles that just repeat the link text. For example, if your link text already says download annual report PDF, you do not need a title that says the same thing. Understanding the proper use of the title attribute demonstrates attention to user experience and accessibility, which are important topics in web development interviews. It shows you understand how to create links that work well for all users, including those using assistive technologies.
Example code
<!-- Title provides context for brief link text -->
<a href="https://example.com" title="Visit Example Company's Official Website">Example</a>
<!-- Title describes file details -->
<a href="report.pdf" title="Download Annual Report 2024 (PDF, 2.5 MB)" download>Download Report</a>
<!-- Title for external link warning -->
<a href="https://external-site.com" title="External link - Opens in new window" target="_blank" rel="noopener noreferrer">Visit Partner Site</a>
<!-- Title for icon-only link -->
<a href="/help" title="Help and Documentation">
<img src="help-icon.png" alt="Help">
</a>
<!-- Title adds clarity -->
<a href="/products" title="Browse our full product catalog">Products</a>
<!-- BAD: Redundant title -->
<a href="contact.html" title="Contact Us">Contact Us</a>
<!-- Better: More informative -->
<a href="contact.html" title="Send us a message or find our office locations">Contact Us</a>