<!DOCTYPE html><htmllang="en"data-bs-theme="auto"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width, initial-scale=1"><metaname="description"content="Documentation and examples for adding custom Bootstrap tooltips with CSS and JavaScript using CSS3 for animations and data-bs-attributes for local title storage."><metaname="author"content="Mark Otto, Jacob Thornton, and Bootstrap contributors"><metaname="generator"content="Astro v5.6.1"><metaname="docsearch:language"content="en"><metaname="docsearch:version"content="5.3"><linkrel="canonical"href="https://getbootstrap.com/docs/5.3/components/tooltips/"><linkrel="preconnect"href="https://AK7KMZKZHQ-dsn.algolia.net"crossorigin><title>Tooltips · Bootstrap v5.3</title><scriptsrc="/docs/5.3/assets/js/color-modes.js"></script><linkrel="stylesheet"href="https://cdn.jsdelivr.net/npm/@docsearch/css@3"><linkhref="/docs/5.3/dist/css/bootstrap.min.css"rel="stylesheet"integrity="sha384-SgOJa3DmI69IUzQ2PVdRZhwQ+dy64/BUtbMJw1MZ8t5HZApcHrRKUc4W0kG879m7"><linkrel="apple-touch-icon"href="/docs/5.3/assets/img/favicons/apple-touch-icon.png"sizes="180x180"><linkrel="icon"href="/docs/5.3/assets/img/favicons/favicon-32x32.png"sizes="32x32"type="image/png"><linkrel="icon"href="/docs/5.3/assets/img/favicons/favicon-16x16.png"sizes="16x16"type="image/png"><linkrel="manifest"href="/docs/5.3/assets/img/favicons/manifest.json"><linkrel="mask-icon"href="/docs/5.3/assets/img/favicons/safari-pinned-tab.svg"color="#712cf9"><linkrel="icon"href="/docs/5.3/assets/img/favicons/favicon.ico"><metaname="theme-color"content="#712cf9"><metaname="twitter:card"content="summary_large_image"><metaname="twitter:site"content="@getbootstrap"><metaname="twitter:creator"content="@getbootstrap"><metaname="twitter:title"content="Tooltips"><metaname="twitter:description"content="Documentation and examples for adding custom Bootstrap tooltips with CSS and JavaScript using CSS3 for animations and data-bs-attributes for local title storage."><metaname="twitter:image"content="https://getbootstrap.com/docs/5.3/assets/brand/bootstrap-social.png"><metaproperty="og:url"content="https://getbootstrap.com/docs/5.3/components/tooltips/"><metaproperty="og:title"content="Tooltips"><metaproperty="og:description"content="Documentation and examples for adding custom Bootstrap tooltips with CSS and JavaScript using CSS3 for animations and data-bs-attributes for local title storage."><metaproperty="og:type"content="article"><metaproperty="og:image"content="https://getbootstrap.com/docs/5.3/assets/brand/bootstrap-social.png"><metaproperty="og:image:type"content="image/png"><metaproperty="og:image:width"content="2000"><metaproperty="og:image:height"content="1000"><scriptdefersrc="https://cdn.usefathom.com/script.js"data-site="ITUSEYJG"></script><linkrel="stylesheet"href="/docs/5.3/assets/_slug_.C9dNs6d9.css"></head><bodydata-bs-spy="scroll"data-bs-target="#TableOfContents"><divclass="skippy visually-hidden-focusable overflow-hidden"><divclass="container-xl"><aclass="d-inline-flex p-2 m-1"href="#content">Skip to main content</a><aclass="d-none d-md-inline-flex p-2 m-1"href="#bd-docs-nav">
</a></div><h1class="bd-title mb-0"id="content">Tooltips</h1></div><divclass="bd-subtitle"><p>Documentation and examples for adding custom Bootstrap tooltips with CSS and JavaScript using CSS3 for animations and data-bs-attributes for local title storage.</p>
<li>Tooltips rely on the third party library <ahref="https://popper.js.org/docs/v2/">Popper</a> for positioning. You must include <ahref="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.8/dist/umd/popper.min.js">popper.min.js</a> before <code>bootstrap.js</code>, or use one <code>bootstrap.bundle.min.js</code> which contains Popper.</li>
<li>Triggering tooltips on hidden elements will not work.</li>
<li>Tooltips for <code>.disabled</code> or <code>disabled</code> elements must be triggered on a wrapper element.</li>
<li>When triggered from hyperlinks that span multiple lines, tooltips will be centered. Use <code>white-space: nowrap;</code> on your <code><a></code>s to avoid this behavior.</li>
<li>Tooltips must be hidden before their corresponding elements have been removed from the DOM.</li>
<li>Tooltips can be triggered thanks to an element inside a shadow DOM.</li>
<p>Got all that? Great, let’s see how they work with some examples.</p>
<divclass="bd-callout bd-callout-info"><p>By default, this component uses the built-in content sanitizer, which strips out any HTML elements that are not explicitly allowed. See the <ahref="/docs/5.3/getting-started/javascript/#sanitizer">sanitizer section in our JavaScript documentation</a> for more details.</p></div>
<divclass="bd-callout bd-callout-info"><p>The animation effect of this component is dependent on the <code>prefers-reduced-motion</code> media query. See the <ahref="/docs/5.3/getting-started/accessibility/#reduced-motion">reduced motion section of our accessibility documentation</a>.</p></div>
<p>As mentioned above, you must initialize tooltips before they can be used. One way to initialize all tooltips on a page would be to select them by their <code>data-bs-toggle</code> attribute, like so:</p>
<divclass="bd-example-snippet bd-code-snippet"><divclass="bd-example m-0 border-0 tooltip-demo"><pclass="muted">Placeholder text to demonstrate some <ahref="#"data-bs-toggle="tooltip"data-bs-title="Default tooltip">inline links</a> with tooltips. This is now just filler, no killer. Content placed here just to mimic the presence of <ahref="#"data-bs-toggle="tooltip"data-bs-title="Another tooltip">real text</a>. And all that just to give you an idea of how tooltips would look when used in real-world situations. So hopefully you’ve now seen how <ahref="#"data-bs-toggle="tooltip"data-bs-title="Another one here too">these tooltips on links</a> can work in practice, once you use them on <ahref="#"data-bs-toggle="tooltip"data-bs-title="The last tip!">your own</a> site or project.</p></div><divclass="d-flex align-items-center highlight-toolbar ps-3 pe-2 py-1 border-0 border-top border-bottom"><smallclass="font-monospace text-body-secondary text-uppercase">html</small><divclass="d-flex ms-auto"><buttontype="button"class="btn-edit text-nowrap"title="Try it on StackBlitz"data-sb-js-snippet="true"><svgclass="bi"aria-hidden="true"><usexlink:href="#lightning-charge-fill"></use></svg></button><buttontype="button"class="btn-clipboard mt-0 me-0"title="Copy to clipboard"><svgclass="bi"aria-hidden="true"><usexlink:href="#clipboard"></use></svg></button></div></div><divclass="highlight"><preclass="language-html"><codeclass="language-html"><spanclass="token tag"><spanclass="token tag"><spanclass="token punctuation"><</span>p</span><spanclass="token attr-name">class</span><spanclass="token attr-value"><spanclass="token punctuation attr-equals">=</span><spanclass="token punctuation">"</span>muted<spanclass="token punctuation">"</span></span><spanclass="token punctuation">></span></span>Placeholder text to demonstrate some <spanclass="token tag"><spanclass="token tag"><spanclass="token punctuation"><</span>a</span><spanclass="token attr-name">href</span><spanclass="token attr-value"><spanclass="token punctuation attr-equals">=</span><spanclass="token punctuation">"</span>#<spanclass="token punctuation">"</span></span><spanclass="token attr-name">data-bs-toggle</span><spanclass="token attr-value"><spanclass="token punctuation attr-equals">=</span><spanclass="token punctuation">"</span>tooltip<spanclass="token punctuation">"</span></span><spanclass="token attr-name">data-bs-title</span><spanclass="token attr-value"><spanclass="token punctuation attr-equals">=</span><spanclass="token punctuation">"</span>Default tooltip<spanclass="token punctuation">"</span></span><spanclass="token punctuation">></span></span>inline links<spanclass="token tag"><spanclass="token tag"><spanclass="token punctuation"></</span>a</span><spanclass="token punctuation">></span></span> with tooltips. This is now just filler, no killer. Content placed here just to mimic the presence of <spanclass="token tag"><spanclass="token tag"><spanclass="token punctuation"><</span>a</span><spanclass="token attr-name">href</span><spanclass="token attr-value"><spanclass="token punctuation attr-equals">=</span><spanclass="token punctuation">"</span>#<spanclass="token punctuation">"</span></span><spanclass="token attr-name">data-bs-toggle</span><spanclass="token attr-value"><spanclass="token punctuation attr-equals">=</span><spanclass="token punctuation">"</span>tooltip<spanclass="token punctuation">"</span></span><spanclass="token attr-name">data-bs-title</span><spanclass="token attr-value"><spanclass="token punctuation attr-equals">=</span><spanclass="token punctuation">"</span>Another tooltip<spanclass="token punctuation">"</span></span><spanclass="token punctuation">></span></span>real text<spanclass="token tag"><spanclass="token tag"><spanclass="token punctuation"></</span>a</span><spanclass="token punctuation">></span></span>. And all that just to give you an idea of how tooltips would look when used in real-world situations. So hopefully you’ve now se
<divclass="bd-callout bd-callout-warning"><p>Feel free to use either <code>title</code> or <code>data-bs-title</code> in your HTML. When <code>title</code> is used, Popper will replace it automatically with <code>data-bs-title</code> when the element is rendered.</p></div>
<p>You can customize the appearance of tooltips using <ahref="#variables">CSS variables</a>. We set a custom class with <code>data-bs-custom-class="custom-tooltip"</code> to scope our custom appearance and use it to override a local CSS variable.</p>
<spanclass="token attr-name">data-bs-title</span><spanclass="token attr-value"><spanclass="token punctuation attr-equals">=</span><spanclass="token punctuation">"</span>This top tooltip is themed via CSS variables.<spanclass="token punctuation">"</span></span><spanclass="token punctuation">></span></span>
<p>Hover over the buttons below to see the four tooltips directions: top, right, bottom, and left. Directions are mirrored when using Bootstrap in RTL.</p>
<buttontype="button"class="btn btn-secondary"data-bs-toggle="tooltip"data-bs-placement="top"data-bs-title="Tooltip on top">Tooltip on top</button>
<buttontype="button"class="btn btn-secondary"data-bs-toggle="tooltip"data-bs-placement="right"data-bs-title="Tooltip on right">Tooltip on right</button>
<buttontype="button"class="btn btn-secondary"data-bs-toggle="tooltip"data-bs-placement="bottom"data-bs-title="Tooltip on bottom">Tooltip on bottom</button>
<buttontype="button"class="btn btn-secondary"data-bs-toggle="tooltip"data-bs-placement="left"data-bs-title="Tooltip on left">Tooltip on left</button>
<buttontype="button"class="btn btn-secondary"data-bs-toggle="tooltip"data-bs-html="true"data-bs-title="<em>Tooltip</em> <u>with</u> <b>HTML</b>">Tooltip with HTML</button>
<divclass="bd-example tooltip-demo"><ahref="#"class="d-inline-block"data-bs-toggle="tooltip"data-bs-title="Default tooltip"aria-label="Hover or focus to see default tooltip"><svgxmlns="http://www.w3.org/2000/svg"width="50"height="50"viewBox="0 0 100 100"aria-hidden="true"><rectwidth="100%"height="100%"fill="#563d7c"></rect><circlecx="50"cy="50"r="30"fill="#007bff"></circle></svg></a></div>
<p>As part of Bootstrap’s evolving CSS variables approach, tooltips now use local CSS variables on <code>.tooltip</code> for enhanced real-time customization. Values for the CSS variables are set via Sass, so Sass customization is still supported, too.</p>
<p>The tooltip plugin generates content and markup on demand, and by default places tooltips after their trigger element. Trigger the tooltip via JavaScript:</p>
<divclass="bd-callout bd-callout-warning"><p>Tooltips automatically attempt to change positions when a parent container has <code>overflow: auto</code> or <code>overflow: scroll</code>, but still keeps the original placement’s positioning. Set the <ahref="https://popper.js.org/docs/v2/modifiers/flip/#boundary"><code>boundary</code> option</a> (for the flip modifier using the <code>popperConfig</code> option) to any HTMLElement to override the default value, <code>'clippingParents'</code>, such as <code>document.body</code>:</p><divclass="bd-code-snippet"><divclass="bd-clipboard"><buttontype="button"class="btn-clipboard"><svgclass="bi"role="img"aria-label="Copy"><usexlink:href="#clipboard"></use></svg></button></div><divclass="highlight"><preclass="language-js"><codeis:rawclass="language-js"><spanclass="token keyword">const</span> tooltip <spanclass="token operator">=</span><spanclass="token keyword">new</span><spanclass="token class-name">bootstrap<spanclass="token punctuation">.</span>Tooltip</span><spanclass="token punctuation">(</span><spanclass="token string">'#example'</span><spanclass="token punctuation">,</span><spanclass="token punctuation">{</span>
<spanclass="token literal-property property">boundary</span><spanclass="token operator">:</span> document<spanclass="token punctuation">.</span>body <spanclass="token comment">// or document.querySelector('#boundary')</span>
<p>The required markup for a tooltip is only a <code>data</code> attribute and <code>title</code> on the HTML element you wish to have a tooltip. The generated markup of a tooltip is rather simple, though it does require a position (by default, set to <code>top</code> by the plugin).</p>
<divclass="bd-callout bd-callout-warning"><p><strong>Keep tooltips accessible to keyboard and assistive technology users</strong> by only adding them to HTML elements that are traditionally keyboard-focusable and interactive (such as links or form controls). While other HTML elements can be made focusable by adding <code>tabindex="0"</code>, this can create annoying and confusing tab stops on non-interactive elements for keyboard users, and most assistive technologies currently do not announce tooltips in this situation. Additionally, do not rely solely on <code>hover</code> as the trigger for your tooltips as this will make them impossible to trigger for keyboard users.</p></div>
<divclass="bd-code-snippet"><divclass="bd-clipboard"><buttontype="button"class="btn-clipboard"><svgclass="bi"role="img"aria-label="Copy"><usexlink:href="#clipboard"></use></svg></button></div><divclass="highlight"><preclass="language-html"><codeis:rawclass="language-html"><spanclass="token comment"><!-- HTML to write --></span>
<p>Elements with the <code>disabled</code> attribute aren’t interactive, meaning users cannot focus, hover, or click them to trigger a tooltip (or popover). As a workaround, you’ll want to trigger the tooltip from a wrapper <code><div></code> or <code><span></code>, ideally made keyboard-focusable using <code>tabindex="0"</code>.</p>
<p>As options can be passed via data attributes or JavaScript, you can append an option name to <code>data-bs-</code>, as in <code>data-bs-animation="{value}"</code>. Make sure to change the case type of the option name from “<em>camelCase</em>” to “<em>kebab-case</em>” when passing the options via data attributes. For example, use <code>data-bs-custom-class="beautifier"</code> instead of <code>data-bs-customClass="beautifier"</code>.</p>
<p>As of Bootstrap 5.2.0, all components support an <strong>experimental</strong> reserved data attribute <code>data-bs-config</code> that can house simple component configuration as a JSON string. When an element has <code>data-bs-config='{"delay":0, "title":123}'</code> and <code>data-bs-title="456"</code> attributes, the final <code>title</code> value will be <code>456</code> and the separate data attributes will override values given on <code>data-bs-config</code>. In addition, existing data attributes are able to house JSON values like <code>data-bs-delay='{"show":0,"hide":150}'</code>.</p>
<p>The final configuration object is the merged result of <code>data-bs-config</code>, <code>data-bs-</code>, and <code>js object</code> where the latest given key-value overrides the others.</p>
<divclass="bd-callout bd-callout-warning"><p>Note that for security reasons the <code>sanitize</code>, <code>sanitizeFn</code>, and <code>allowList</code> options cannot be supplied using data attributes.</p></div>
<divclass="table-responsive">
<tableclass="table"><thead><tr><th>Name</th><th>Type</th><th>Default</th><th>Description</th></tr></thead><tbody><tr><td><code>allowList</code></td><td>object</td><td><ahref="/docs/5.3/getting-started/javascript#sanitizer">Default value</a></td><td>Object which contains allowed attributes and tags.</td></tr><tr><td><code>animation</code></td><td>boolean</td><td><code>true</code></td><td>Apply a CSS fade transition to the tooltip.</td></tr><tr><td><code>boundary</code></td><td>string, element</td><td><code>'clippingParents'</code></td><td>Overflow constraint boundary of the tooltip (applies only to Popper’s preventOverflow modifier). By default, it’s <code>'clippingParents'</code> and can accept an HTMLElement reference (via JavaScript only). For more information refer to Popper’s <ahref="https://popper.js.org/docs/v2/utils/detect-overflow/#boundary">detectOverflow docs</a>.</td></tr><tr><td><code>container</code></td><td>string, element, false</td><td><code>false</code></td><td>Appends the tooltip to a specific element. Example: <code>container: 'body'</code>. This option is particularly useful in that it allows you to position the tooltip in the flow of the document near the triggering element -which will prevent the tooltip from floating away from the triggering element during a window resize.</td></tr><tr><td><code>customClass</code></td><td>string, function</td><td><code>''</code></td><td>Add classes to the tooltip when it is shown. Note that these classes will be added in addition to any classes specified in the template. To add multiple classes, separate them with spaces: <code>'class-1 class-2'</code>. You can also pass a function that should return a single string containing additional class names.</td></tr><tr><td><code>delay</code></td><td>number, object</td><td><code>0</code></td><td>Delay showing and hiding the tooltip (ms)—doesn’t apply to manual trigger type. If a number is supplied, delay is applied to both hide/show. Object structure is: <code>delay: { "show": 500, "hide": 100 }</code>.</td></tr><tr><td><code>fallbackPlacements</code></td><td>array</td><td><code>['top', 'right', 'bottom', 'left']</code></td><td>Define fallback placements by providing a list of placements in array (in order of preference). For more information refer to Popper’s <ahref="https://popper.js.org/docs/v2/modifiers/flip/#fallbackplacements">behavior docs</a>.</td></tr><tr><td><code>html</code></td><td>boolean</td><td><code>false</code></td><td>Allow HTML in the tooltip. If true, HTML tags in the tooltip’s <code>title</code> will be rendered in the tooltip. If false, <code>innerText</code> property will be used to insert content into the DOM. Use text if you’re worried about XSS attacks.</td></tr><tr><td><code>offset</code></td><td>array, string, function</td><td><code>[0, 6]</code></td><td>Offset of the tooltip relative to its target. You can pass a string in data attributes with comma separated values like: <code>data-bs-offset="10,20"</code>. When a function is used to determine the offset, it is called with an object containing the popper placement, the reference, and popper rects as its first argument. The triggering element DOM node is passed as the second argument. The function must return an array with two numbers: <ahref="https://popper.js.org/docs/v2/modifiers/offset/#skidding-1">skidding</a>, <ahref="https://popper.js.org/docs/v2/modifiers/offset/#distance-1">distance</a>. For more information refer to Popper’s <ahref="https://popper.js.org/docs/v2/modifiers/offset/#options">offset docs</a>.</td></tr><tr><td><code>placement</code></td><td>string, function</td><td><code>'top'</code></td><td>How to position the tooltip: auto, top, bottom, left, right. When <code>auto</code> is specified, it will dynamically reorient the tooltip. When a function is used to determine the placement, it is called with the tooltip DOM node as its first argument and the triggering element DOM node as its seco
<divclass="bd-callout bd-callout-info"><h4id="data-attributes-for-individual-tooltips">Data attributes for individual tooltips<aclass="anchor-link"href="#data-attributes-for-individual-tooltips"></a></h4><p>Options for individual tooltips can alternatively be specified through the use of data attributes, as explained above.</p></div>
<h4id="using-function-with-popperconfig">Using function with <code>popperConfig</code><aclass="anchor-link"href="#using-function-with-popperconfig"></a></h4>
<divclass="bd-callout bd-callout-danger"><p><strong>All API methods are asynchronous and start a transition.</strong> They return to the caller as soon as the transition is started, but before it ends. In addition, a method call on a transitioning component will be ignored. <ahref="/docs/5.3/getting-started/javascript/#asynchronous-functions-and-transitions">Learn more in our JavaScript docs.</a></p></div>
<divclass="table-responsive">
<tableclass="table"><thead><tr><th>Method</th><th>Description</th></tr></thead><tbody><tr><td><code>disable</code></td><td>Removes the ability for an element’s tooltip to be shown. The tooltip will only be able to be shown if it is re-enabled.</td></tr><tr><td><code>dispose</code></td><td>Hides and destroys an element’s tooltip (Removes stored data on the DOM element). Tooltips that use delegation (which are created using <ahref="#options">the <code>selector</code> option</a>) cannot be individually destroyed on descendant trigger elements.</td></tr><tr><td><code>enable</code></td><td>Gives an element’s tooltip the ability to be shown. <strong>Tooltips are enabled by default.</strong></td></tr><tr><td><code>getInstance</code></td><td><em>Static</em> method which allows you to get the tooltip instance associated with a DOM element.</td></tr><tr><td><code>getOrCreateInstance</code></td><td><em>Static</em> method which allows you to get the tooltip instance associated with a DOM element, or create a new one in case it wasn’t initialized.</td></tr><tr><td><code>hide</code></td><td>Hides an element’s tooltip. <strong>Returns to the caller before the tooltip has actually been hidden</strong> (i.e. before the <code>hidden.bs.tooltip</code> event occurs). This is considered a “manual” triggering of the tooltip.</td></tr><tr><td><code>setContent</code></td><td>Gives a way to change the tooltip’s content after its initialization.</td></tr><tr><td><code>show</code></td><td>Reveals an element’s tooltip. <strong>Returns to the caller before the tooltip has actually been shown</strong> (i.e. before the <code>shown.bs.tooltip</code> event occurs). This is considered a “manual” triggering of the tooltip. Tooltips with zero-length titles are never displayed.</td></tr><tr><td><code>toggle</code></td><td>Toggles an element’s tooltip. <strong>Returns to the caller before the tooltip has actually been shown or hidden</strong> (i.e. before the <code>shown.bs.tooltip</code> or <code>hidden.bs.tooltip</code> event occurs). This is considered a “manual” triggering of the tooltip.</td></tr><tr><td><code>toggleEnabled</code></td><td>Toggles the ability for an element’s tooltip to be shown or hidden.</td></tr><tr><td><code>update</code></td><td>Updates the position of an element’s tooltip.</td></tr></tbody></table></div>
<divclass="bd-callout bd-callout-info"><p>The <code>setContent</code> method accepts an <code>object</code> argument, where each property-key is a valid <code>string</code> selector within the tooltip template, and each related property-value can be <code>string</code> | <code>element</code> | <code>function</code> | <code>null</code></p></div>
<tableclass="table"><thead><tr><th>Event</th><th>Description</th></tr></thead><tbody><tr><td><code>hide.bs.tooltip</code></td><td>This event is fired immediately when the <code>hide</code> instance method has been called.</td></tr><tr><td><code>hidden.bs.tooltip</code></td><td>This event is fired when the tooltip has finished being hidden from the user (will wait for CSS transitions to complete).</td></tr><tr><td><code>inserted.bs.tooltip</code></td><td>This event is fired after the <code>show.bs.tooltip</code> event when the tooltip template has been added to the DOM.</td></tr><tr><td><code>show.bs.tooltip</code></td><td>This event fires immediately when the <code>show</code> instance method is called.</td></tr><tr><td><code>shown.bs.tooltip</code></td><td>This event is fired when the tooltip has been made visible to the user (will wait for CSS transitions to complete).</td></tr></tbody></table></div>
Designed and built with all the love in the world by the <ahref="/docs/5.3/about/team">Bootstrap team</a> with the help of <ahref="https://github.com/twbs/bootstrap/graphs/contributors">our contributors</a>.
</li><liclass="mb-2">
Code licensed <ahref="https://github.com/twbs/bootstrap/blob/main/LICENSE"target="_blank"rel="license noopener">MIT</a>, docs <ahref="https://creativecommons.org/licenses/by/3.0/"target="_blank"rel="license noopener">CC BY 3.0</a>.