0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…
Advisory text shown as a mouse-hover tooltip and used as an accessible name or description. Good for abbr and iframe; never the only place for important text.
Overview
The title attribute holds advisory text about an element. Desktop browsers show it as a tooltip after the mouse rests on the element. Assistive technology uses it too: as the element's name when nothing else names it, otherwise as its description. This is the titleattribute, not the <title> element in <head>.
Applies to: every element (it is a global attribute). On <link>, <style>, <abbr> and <dfn> it has extra meaning (see Values).
Abbreviations and icon-only buttons
123456789
<p>The <abbrtitle="World Health Organization">WHO</abbr> published joint guidance.</p><!-- title alone: mouse-only tooltip, also the button's name --><buttontype="button"title="Print this page"><icon-wcname="printer"></icon-wc></button><!-- tool-tip shows the same text on keyboard focus --><tool-tip><buttontype="button"title="Copy link to this page"><icon-wcname="link"></icon-wc></button></tool-tip>
Values
Value
Meaning
Any text
Advisory text for this element. Line feeds ( ) start new lines in the tooltip.
"" (empty)
No advisory text, and stops an ancestor's title from applying here.
Absent
Inherits the nearest ancestor's title for the tooltip.
Special meanings:
<abbr title> and <dfn title>: the expansion or the term being defined, and nothing else.
<link rel="stylesheet" title> and <style title>: names a stylesheet set; rel="alternate stylesheet" makes it switchable.
<iframe title>: the frame's accessible name, announced before the user enters it.
Examples
Abbreviations
Expand on first use
1234
<p> Use <abbrtitle="Cascading Style Sheets">CSS</abbr> for presentation and<abbrtitle="HyperText Markup Language">HTML</abbr> for structure.</p>
The tooltip is mouse-only, so also write the expansion out in the text the first time an abbreviation appears.
Naming an iframe
iframe title
1234
<iframesrc="https://www.openstreetmap.org/export/embed.html?bbox=-0.13,51.50,-0.12,51.51"title="Map of the office location near Trafalgar Square"loading="lazy"></iframe>
Alternatives
For anything the user needs, use visible text or a proper name and description.
Instead of title
1234567891011121314
<!-- Visible text --><buttontype="button"><icon-wcname="printer"></icon-wc> Print</button><!-- Icon-only: a name every user gets, plus a tooltip --><tool-tipcontent="Print this page"><buttontype="button"aria-label="Print this page"><icon-wcname="printer"></icon-wc></button></tool-tip><!-- Help text: visible, and wired to the field by form-field --><form-field><labelfor="tax-id">Tax ID</label><inputtype="text"id="tax-id"name="tax-id"><outputclass="hint"for="tax-id">Your 9-digit federal tax identification number.</output></form-field>
abbr[title] gets a dotted underline and a help cursor; the underline turns the interactive colour on hover. An <abbr> without title stays plain (src/native-elements/inline-semantics/styles.css).
Print expands abbreviations. VB's print stylesheet appends the expansion after each abbr[title], for example "WHO (World Health Organization)" (src/utils/print.css).
Icon-only buttons. A button whose only child is an <icon-wc> and that has aria-label, aria-labelledby or title gets square padding (src/native-elements/button/styles.css).
<tool-tip> upgrades title. When it has no <template data-tooltip> or content, it uses the trigger's title as its text. It removes the title while upgraded to prevent a double tooltip, copies it to aria-label if it was the trigger's only name, and puts it back when removed (src/web-components/tool-tip/logic.js).
Shortcut labels.data-hotkey action bindings name themselves from the element's text, then placeholder, then title, unless you set data-hotkey-label (src/utils/hotkey-action-init.js).
Accessibility
Name or description. In the accessible-name calculation title is the last resort: if nothing else names the element (content, aria-label, a <label>), title becomes its name. Otherwise it becomes its description and is read after the name.
The real problem is who can see it. The tooltip needs a mouse. Keyboard and touch users never see it, so text that only lives in title is missing for them.
Never the only label for a form field. A field named only by title has a name for screen readers but no visible label (WCAG 3.3.2 Labels or Instructions).
Do not repeat visible text. A title equal to the element's text adds nothing and may be read twice.
Every iframe needs a name.title is the usual way (WCAG 4.1.2).
Gotchas
Inheritance surprises. A title on a container shows on every descendant. Use title="" on a child to stop it.
Timing and style are fixed. You cannot change the delay, position or appearance of the browser tooltip.
Plain text only. No markup; line feeds work.
Related
<tool-tip> — keyboard-accessible tooltips; uses title as a fallback.