Why the title attribute is a fragile tool

The title attribute gives a native tooltip, but only on devices with a mouse pointer, and the tooltip appears on hover.

<div title="The Title">
  I'm a div with a `title`
</div>
Screenshot of standard text saying I'm a div with a title. A light gray tooltip is floating above the text next to the cursor that says The Title.

That limits the feature to sighted mouse users. Common shorthand examples such as dates and times on elements can gain a small usability boost this way, but not much more. Ire Aderinokun examined the <abbr> element, a typical citation for the attribute, and concluded that title alone is not enough, proposing a JavaScript-enhanced pattern instead. She also notes that JAWS exposes a setting to announce titles, which appears to be off by default. How useful title really is for screen readers remains nuanced.

SVG needs its own title element

Setting a title attribute directly on an SVG does not produce a tooltip on hover:

<!-- Incorrect usage -->
<svg title="Checkout">
</svg>

A child <title> element inside the <svg> is required:

<!-- Correct usage -->
<svg>
  <title id="unique-id">Checkout</title>
  
  <!-- More detail -->
  <desc>A shopping cart icon with baguettes and broccoli in the cart.</desc>
</svg>

Firefox 79 was the browser that added support for this behavior. With this form, the hover area that triggers the tooltip is the full rectangle of the <svg>.

The <use> exception

A report described tooltips appearing only over the filled pixels of an SVG, never over transparent ones, which seemed impossible to reproduce locally at first. The cause is a <title> placed inside a <use> element: the title then applies only to the pixels that arrive through that <use>. Removing the title on the white portion leaves the black portion with a tooltip that shows up only over its own black pixels. The behavior appears consistent across browsers.

For SVGs where titles are attached this way, that pixel-scoped tooltip area is worth keeping in mind.