Tooltip
Short labels on hover and keyboard focus. Icon buttons get them automatically from their aria-label — nothing to add.
Colors
Dark by default. Give the trigger a color with data-moey-tooltip-theme, and a strength with data-moey-tooltip-style — subtle, soft, solid, vivid or deep, like buttons. Light and dark mode are handled by the theme.
<button data-moey-tooltip="Saved" data-moey-tooltip-theme="green"> <!-- the soft default fill -->
<button data-moey-tooltip="Saved" data-moey-tooltip-theme="green" data-moey-tooltip-style="subtle"> <!-- *-100 tint -->
<button data-moey-tooltip="Saved" data-moey-tooltip-theme="green" data-moey-tooltip-style="vivid"> <!-- full color -->
<!-- Icon buttons: automatic, from aria-label (or title) -->
<button class="btn btn-ghost btn-icon" aria-label="Notifications">
<i class="mi mi-bell"></i>
</button>
<!-- Anything else -->
<button class="btn" data-moey-tooltip="Copies a link anyone in your team can open">Share</button>
<!-- Options -->
<button … data-moey-placement="bottom"> <!-- top (default) · bottom · start · end · auto -->
<button … data-moey-shortcut="⌘K"> <!-- keyboard hint -->
<button … data-moey-tooltip-style="light"> <!-- light instead of dark -->
<button … data-moey-tooltip-arrow="false"> <!-- no arrow (or on <body> for the whole page) -->
<button class="btn-icon" … data-moey-tooltip="false"> <!-- no tooltip -->
- Feels like an app — a short delay the first time, then instant while you move along a toolbar. Keyboard focus shows it right away; touch screens don't show tooltips.
- Arrow — points at the element, even when the tooltip had to shift to stay on screen.
data-moey-tooltip-arrow="false"hides it (on<body>: for the whole page). - Always on top & on screen — it uses the top layer (above dialogs and menus). A set side flips to the opposite one when there's no room;
autosimply picks whichever of above / below has more space (or beside, if neither fits). - No double tooltips — a
titleis taken over, so the browser's own tooltip doesn't appear as well. - Collapsed sidebar — in an icon-only
.appsidebar, every link shows its label as a tooltip. - Accessible — the text becomes the element's description (or its label if it has none). Esc hides it.
Keep tooltips short and never put the only copy of important information in one — people on touch screens won't see it. From code: Moey.tooltip(element) shows one, Moey.tooltip(null) hides it.
Disabled buttons
Disabled buttons get no mouse events, so put the tooltip on a wrapper.
<span class="inline-block" data-moey-tooltip="Add a payment method first" tabindex="0">
<button class="btn btn-default" disabled>Publish store</button>
</span>
In running text
For definitions and abbreviations: .tooltip-term gives the word a quiet dashed underline and the help cursor, and tabindex="0" lets keyboard users reach it.
Your AOV went up 12% this month.
<p class="m-0">Your <span data-moey-tooltip="Average order value: revenue ÷ orders" class="tooltip-term" tabindex="0">AOV</span> went up 12% this month.</p>