Tooltips
<button class="btn" data-variant="outline" data-tooltip="Add to library">Hover</button>
A tooltip is one attribute and needs no script
data-tooltip on an element shows its text above the element on hover. The text is plain text taken from the attribute.
data-side puts it above, below, left or right
<div class="flex flex-wrap items-center justify-center gap-3">
<button class="btn" data-variant="outline" data-tooltip="Above, the default" data-side="top">Top</button>
<button class="btn" data-variant="outline" data-tooltip="Below" data-side="bottom">Bottom</button>
<button class="btn" data-variant="outline" data-tooltip="To the left" data-side="left">Left</button>
<button class="btn" data-variant="outline" data-tooltip="To the right" data-side="right">Right</button>
</div>
data-align lines it up with the start, the centre or the end of the element
<div class="flex flex-wrap items-center justify-center gap-3">
<button class="btn" data-variant="outline" data-tooltip="Lined up with the start" data-align="start">Start</button>
<button class="btn" data-variant="outline" data-tooltip="Centred, the default" data-align="center">Center</button>
<button class="btn" data-variant="outline" data-tooltip="Lined up with the end" data-align="end">End</button>
</div>
An icon button keeps its aria-label: the tooltip is not its name
It works on any element that can hold content: a badge, an icon, a word
Paid
MRR
<div class="flex flex-wrap items-center justify-center gap-4 text-sm">
<span class="badge" data-variant="success" data-tooltip="Paid on Oct. 3, 2026">Paid</span>
<span data-tooltip="Verified by 3D Secure"><i class="icon icon-shield-check text-success" aria-hidden="true"></i></span>
<span class="underline decoration-dotted underline-offset-4" data-tooltip="Monthly recurring revenue" data-align="end">MRR</span>
</div>
A field cannot draw a tooltip itself, so the attribute goes on a wrapper
<span class="inline-flex" data-tooltip="Letters and numbers only" data-align="start">
<input class="input w-56" type="text" placeholder="Coupon code" aria-label="Coupon code" />
</span>
Long text stays on one line and is cut off at 320px
<button class="btn" data-variant="outline" data-tooltip="This payment was captured by the gateway on the first attempt and settled the next business day" data-align="end">Long text</button>
What a tooltip does not do
| Limit | What to do |
|---|---|
| It shows on hover only. Keyboard focus does not show it, and a touch screen has no hover. | Never put information in a tooltip that is not also on the page or in an aria-label. |
| A screen reader does not read it. | Name an icon button with aria-label. |
| It is one line of plain text, cut off at 320px. It cannot hold a link, a button or formatting. | Use a popover for anything longer or anything to click. |
An input, select, textarea or img cannot draw one. |
Put data-tooltip on an element around it. |
| A scrolling area cuts it off at its edge. | Choose the data-side that points into the area, or place the element outside it. |
| Near the right edge of the page it reaches past the edge, and the page scrolls sideways. | Give that element data-align="end". |
| It stays on the side it was given, even at the edge of the window. | Choose data-side and data-align for where the element sits. |
API Reference
Attributes
| Attribute | On | Values | Default | Description |
|---|---|---|---|---|
| data-tooltip | any element that can hold content | text | none | The text shown on hover. Plain text, one line. |
| data-side | the same element | "top", "bottom", "left", "right", "inline-start", "inline-end" | "top" | The side of the element the tooltip is on. inline-start and inline-end follow the reading direction. |
| data-align | the same element | "start", "center", "end" | "center" | Which edge of the element the tooltip lines up with. |
A tooltip is drawn by the stylesheet as the element's ::before, so an element that already uses ::before cannot have one.
In a collapsed sidebar the sidebar script places the tooltips, so the scrolling list does not cut them off.