Get $50+ off for Black Friday!

Tooltips

Overview

Tooltips are powered by Floating UI. We've wrapped them in a Stimulus controller so you can easily add them anywhere in your application. See also Clipboard which uses tooltips.

Add a data-controller="tooltip" data-tooltip-content="My tooltip" to the element you want to add the tooltip to. You can set options using data attributes without writing any JS.

Tooltip content is shown as plain text. If the tooltip needs markup you wrote yourself, add data-tooltip-allow-html-value="true". Never allow HTML for content that includes anything a user or another system controls, since it would run as HTML on your page.

If the markup has to include such a value, sanitize it on the server first with Rails' sanitize helper, allowing only the tags you need, and then opt in:

<%= tag.span "?", data: {
  controller: "tooltip",
  tooltip_content_value: sanitize(hint, tags: %w[strong em br code]),
  tooltip_allow_html_value: true
} %>

You can also specify the placement of the tooltip with data-tooltip-placement-value="right".