search results:

    • Standard
    • React
    Pricing Learn Community
    • + D
    • Light
    • Dark
    • System
    logo TW Elements
    • Getting started
      • Quick start
      • Tutorials
      • Design system
      • Local installation
      • Optimization
      • Dark mode
      • Theming
      • Changelog
      • Migrating to v2
      • Internationalization guide
      • Class customization
      • Icons Integration
    • CommercialNew
      • Pricing
      • License
      • Installation
      • Git & repository
      • Premium Support
    • Integrations
      • Angular
      • ASP.NET
      • Django
      • Express
      • Laravel
      • Next
      • Nuxt
      • Qwik
      • React
      • Remix
      • Solid
      • Svelte
      • SvelteKit
      • Vue
    • Content & styles
      • Animations
      • Animations Extended
      • Colors
      • Dividers
      • Figures
      • Headings
      • Hover effects
      • Icons
      • Images
      • Mask
      • Shadows
      • Typography
    • Navigation
      • Breadcrumbs
      • Footer
      • Headers
      • Mega menu
      • Navbar
      • Offcanvas
      • Pagination
      • Pills
      • Scrollspy
      • Sidenav
      • Tabs
    • Components
      • Accordion
      • Alerts
      • Avatar
      • Badges
      • Button group
      • Buttons
      • Cards
      • Carousel
      • Chips
      • Collapse
      • Dropdown
      • Gallery
      • Jumbotron
      • Lightbox
      • Link
      • List group
      • Modal
      • Notifications
      • Paragraphs
      • Placeholders
      • Popconfirm
      • Popover
      • Progress
      • Rating
      • Scroll back to top button
      • Social buttons
      • Spinners
      • Stepper
      • Testimonials
      • Timeline
      • Toast
      • Tooltip
      • Video
      • Video carousel
    • Forms
      • Autocomplete
      • Checkbox
      • Datepicker
      • Datetimepicker
      • File input
      • Form templates
      • Input Group
      • Inputs
      • Login form
      • Multi range slider
      • Radio
      • Range
      • Registration form
      • Search
      • Select
      • Switch
      • Textarea
      • Timepicker
      • Validation
    • Data
      • Charts
      • Charts advanced
      • Datatables
      • Tables
    • Methods
      • Clipboard
      • Infinite scroll
      • Lazy loading
      • Loading management
      • Ripple
      • Scrollbar
      • Smooth scroll
      • Sticky
      • Touch
    • Design Blocks
      • Admin Charts
      • Admin Complex
      • Admin Forms
      • Admin Maps
      • Admin Navigation
      • Admin tables
      • Banners
      • Contact
      • Content
      • CTA
      • FAQ
      • Features
      • Headers
      • Hero / Intro sections
      • Logo clouds
      • Mega menu
      • News
      • Newsletter
      • Pricing
      • Projects
      • Stats
      • Stats admin
      • Team
      • Testimonials
    • Tools
      • Button generator
      • Card generator
      • Flexbox generator
      • Footer generator
      • Form builder
      • Grid generator
      • Icon generator
      • Instagram Filters generator
      • Logo generator
      • Table generator
      • Typography generator
    • Coming Soon
      • Angular
      • Builder
      • Templates
      • Vue
    • Resources
      • Playground
      • YouTube Channel
      • Private FB Group
      • Newsletter
      • UI Design course New
      • UI / UX tips
    • Overview
    • API

    Tooltip

    Tailwind CSS Tooltip

    Use responsive tooltip component with helper examples for tooltip ui, tooltip on hover, disabled tooltip, direction & more. Free download, open-source license.

    Required ES init: Tooltip *
    * UMD autoinits are enabled by default. This means that you don't need to initialize the component manually. However if you are using TW Elements ES format then you should pass the required components to the initTWE method.

    Basic example

    To get started with using tooltips all you need to do is add the data-twe-target="tooltip" data attribute to an element where elementId is the id of the tooltip component. In the following example you can see the button that will trigger the tooltip element to be shown when hovered or focused.

    Hover the link to see the tooltip

    • HTML
    • javascript
            
                
          <p>
            Hover the link to see the
            <a
              href="#"
              class="text-primary dark:text-primary-400"
              data-twe-toggle="tooltip"
              title="Hi! I'm tooltip"
              >tooltip</a
            >
          </p>
          
            
        
            
                
          // Initialization for ES Users
          import {
            Tooltip,
            initTWE,
          } from "tw-elements";
    
          initTWE({ Tooltip });
          
            
        

    Hey there 👋 we're excited about TW elements and want to see it grow! If you enjoy it, help the project grow by sharing it with your peers. Every share counts, thank you!

    Four directions

    • HTML
    • javascript
            
                
          <button
            type="button"
            class="inline-block rounded bg-primary-100 px-6 pb-2 pt-2.5 text-xs font-medium uppercase leading-normal text-primary-700 transition duration-150 ease-in-out hover:bg-primary-accent-200 focus:bg-primary-accent-200 focus:outline-none focus:ring-0 active:bg-primary-accent-200 dark:bg-primary-300 dark:hover:bg-primary-400 dark:focus:bg-primary-400 dark:active:bg-primary-400"
            data-twe-toggle="tooltip"
            data-twe-placement="top"
            data-twe-ripple-init
            data-twe-ripple-color="light"
            title="Tooltip on top">
            Tooltip on top
          </button>
          <button
            type="button"
            class="inline-block rounded bg-primary-100 px-6 pb-2 pt-2.5 text-xs font-medium uppercase leading-normal text-primary-700 transition duration-150 ease-in-out hover:bg-primary-accent-200 focus:bg-primary-accent-200 focus:outline-none focus:ring-0 active:bg-primary-accent-200 dark:bg-primary-300 dark:hover:bg-primary-400 dark:focus:bg-primary-400 dark:active:bg-primary-400"
            data-twe-toggle="tooltip"
            data-twe-placement="right"
            data-twe-ripple-init
            data-twe-ripple-color="light"
            title="Tooltip on right">
            Tooltip on right
          </button>
          <button
            type="button"
            class="inline-block rounded bg-primary-100 px-6 pb-2 pt-2.5 text-xs font-medium uppercase leading-normal text-primary-700 transition duration-150 ease-in-out hover:bg-primary-accent-200 focus:bg-primary-accent-200 focus:outline-none focus:ring-0 active:bg-primary-accent-200 dark:bg-primary-300 dark:hover:bg-primary-400 dark:focus:bg-primary-400 dark:active:bg-primary-400"
            data-twe-toggle="tooltip"
            data-twe-placement="bottom"
            data-twe-ripple-init
            data-twe-ripple-color="light"
            title="Tooltip on bottom">
            Tooltip on bottom
          </button>
          <button
            type="button"
            class="inline-block rounded bg-primary-100 px-6 pb-2 pt-2.5 text-xs font-medium uppercase leading-normal text-primary-700 transition duration-150 ease-in-out hover:bg-primary-accent-200 focus:bg-primary-accent-200 focus:outline-none focus:ring-0 active:bg-primary-accent-200 dark:bg-primary-300 dark:hover:bg-primary-400 dark:focus:bg-primary-400 dark:active:bg-primary-400"
            data-twe-toggle="tooltip"
            data-twe-placement="left"
            data-twe-ripple-init
            data-twe-ripple-color="light"
            title="Tooltip on left">
            Tooltip on left
          </button>
          
            
        
            
                
          // Initialization for ES Users
          import {
            Ripple,
            Tooltip,
            initTWE,
          } from "tw-elements";
          
          initTWE({ Ripple, Tooltip });
          
            
        

    With custom HTML

    • HTML
    • javascript
            
                
          <button
            type="button"
            class="inline-block rounded bg-primary-100 px-6 pb-2 pt-2.5 text-xs font-medium uppercase leading-normal text-primary-700 transition duration-150 ease-in-out hover:bg-primary-accent-200 focus:bg-primary-accent-200 focus:outline-none focus:ring-0 active:bg-primary-accent-200 dark:bg-primary-300 dark:hover:bg-primary-400 dark:focus:bg-primary-400 dark:active:bg-primary-400"
            data-twe-toggle="tooltip"
            data-twe-html="true"
            data-twe-ripple-init
            data-twe-ripple-color="light"
            title="<em>Tooltip</em> <u>with</u> <b>HTML</b>">
            Tooltip with html
          </button>
          
            
        
            
                
          // Initialization for ES Users
          import {
            Ripple,
            Tooltip,
            initTWE,
          } from "tw-elements";
          
          initTWE({ Ripple, Tooltip });
          
            
        

    Disabled

    Initialize the tooltip with the disabled option specified.

    • HTML
    • javascript
            
                
          <span
            class="inline-block"
            tabindex="0"
            data-twe-toggle="tooltip"
            title="Disabled tooltip">
            <button
              class="pointer-events-none inline-block rounded bg-primary px-6 pb-2 pt-2.5 text-xs font-medium uppercase leading-normal text-white shadow-[0_4px_9px_-4px_#3b71ca] transition duration-150 ease-in-out hover:bg-primary-600 hover:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] focus:bg-primary-600 focus:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] focus:outline-none focus:ring-0 active:bg-primary-700 active:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] disabled:opacity-70 dark:shadow-[0_4px_9px_-4px_rgba(59,113,202,0.5)] dark:hover:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)] dark:focus:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)] dark:active:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)]"
              type="button"
              disabled>
              Disabled button
            </button>
          </span>
          
            
        
            
                
          // Initialization for ES Users
          import {
            Tooltip,
            initTWE,
          } from "tw-elements";
          
          initTWE({ Tooltip })
          
            
        

    Related resources

    Tutorials:

    hover state text utility first buttons rounded corners sizing badges

    Extended Docs:

    animations colors hover effects images alerts badges buttons collapse dropdown modal notifications popover social buttons search select charts box sizing center text colors display flex position spacing text bold text color visibility hidden z index

    Generators and builders:

    Form drag & drop Typography SVG icon Instagram Filters button card table flexbox logo grid footer

    Design System (Figma):

    introduction size matters low contrast vs low aesthetics beyond borders let it breathe do not start with the roof project personality design system plan the process principles tips and tricks
    • Basic example
    • Four directions
    • With custom HTML
    • Disabled
    • Related resources

    Tooltip - API


    Import

    Importing components depends on how your application works. If you intend to use the TW elements ES format, you must first import the component and then initialize it with the initTWE method. If you are going to use the UMD format, just import the tw-elements package.

    • javascript
    • umd
            
                
            import { Tooltip, initTWE } from "tw-elements";
            initTWE({ Tooltip });
            
            
        
            
                
            import "tw-elements";
            
            
        

    Usage

    Via data attributes

    • HTML
            
                
            <p>
              Hover the link to see the
              <a href="#" data-twe-toggle="tooltip" title="Hi! I'm tooltip"
                >tooltip</a
              >
            </p>
            
            
        

    Via JavaScript

    • javascript
    • umd
            
                
              const exampleEl = document.getElementById('example');
              const tooltip = new Tooltip(exampleEl);
            
            
        
            
                
              const exampleEl = document.getElementById('example');
              const tooltip = new twe.Tooltip(exampleEl);
            
            
        

    Overflow auto and scroll

    Tooltip position attempts to automatically change when a parent container has overflow: auto or overflow: scroll like our .table-responsive, but still keeps the original placement’s positioning. To resolve, set the boundary option to anything other than default value, 'scrollParent', such as 'window':

    • javascript
    • umd
            
                
              const exampleEl = document.getElementById('example');
              const tooltip = new Tooltip(exampleEl, {
                boundary: 'window'
              });
            
            
        
            
                
              const exampleEl = document.getElementById('example');
              const tooltip = new twe.Tooltip(exampleEl, {
                boundary: 'window'
              });
            
            
        

    Markup

    The required markup for a tooltip is only a data attribute and title 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 top by the plugin).

    Making tooltips work for keyboard and assistive technology users

    You should only add tooltips to HTML elements that are traditionally keyboard-focusable and interactive (such as links or form controls). Although arbitrary HTML elements (such as <span>s) can be made focusable by adding the tabindex="0" attribute, this will add potentially annoying and confusing tab stops on non-interactive elements for keyboard users, and most assistive technologies currently do not announce the tooltip in this situation. Additionally, do not rely solely on hover as the trigger for your tooltip, as this will make your tooltips impossible to trigger for keyboard users.

    • HTML
            
                
            <!-- HTML to write -->
            <a href="#" data-twe-toggle="tooltip" title="Some tooltip text!"
              >Hover over me</a
            >
    
            <!-- Generated markup by the plugin -->
            <div role="tooltip">
              <div>Some tooltip text!</div>
            </div>
            
            
        

    Options

    Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-twe-, as in data-twe-toggle="tooltip".

    Note: For security reasons the sanitize, sanitizeFn and whiteList options cannot be supplied using data attributes.

    Name Type Default Description
    container string/element/boolean false Appends the tooltip to a specific element. Example: container: 'body'. 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.
    html boolean false Insert HTML into the tooltip. If false, innerText property will be used to insert content into the DOM. Use text if you're worried about XSS attacks.
    placement string/function 'right' How to position the tooltip - auto | top | bottom | left | right. When auto 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 second. The this context is set to the tooltip instance.
    selector string/boolean false If a selector is provided, tooltip objects will be delegated to the specified targets. In practice, this is used to enable dynamic HTML content to have tooltips added. See this and an informative example.
    template string ` <div class="opacity-0 transition-opacity duration-300 ease-in-out absolute z-[1080] block m-0 text-sm not-italic font-normal text-left no-underline underline-offset-auto normal-case leading-6 tracking-normal break-normal whitespace-normal" role="tooltip"> <div data-twe-tooltip-inner-ref class="max-w-[200px] text-sm py-1.5 px-4 text-white text-center bg-[#6d6d6d] rounded"></div> </div> ` Base HTML to use when creating the tooltip. The tooltip's title will be injected into the .tooltip-header. The tooltip's content will be injected into the .tooltip-body.
    title string/element/function - Default title value if title attribute isn't present. If a function is given, it will be called with its this reference set to the element that the tooltip is attached to.
    trigger string 'click'

    How tooltip is triggered - click | hover | focus | manual. You may pass multiple triggers; separate them with a space.


    'manual' indicates that the tooltip will be triggered programmatically via the .tooltip('show'), .tooltip('hide') and .tooltip('toggle') methods; this value cannot be combined with any other trigger.

    offset number/string 0 Offset of the tooltip relative to its target. For more information refer to Popper's offset docs.
    fallbackPlacement string/array 'flip' Allow to specify which position Popper will use on fallback. For more information refer to Popper's behavior docs.
    boundary element/string 'clippingParents' Overflow constraint boundary of the tooltip (applies only to Popper's preventOverflow modifier). Accepts the values of 'viewport', 'window', 'scrollParent', or an HTMLElement reference (via JavaScript only). For more information refer to Popper's detectOverflow docs.
    sanitize boolean true Enable or disable the sanitization. If activated 'template', 'content' and 'title' options will be sanitized.
    whiteList object Default value Object which contains allowed attributes and tags.
    sanitizeFn null/function null Here you can supply your own sanitize function. This can be useful if you prefer to use a dedicated library to perform sanitization.
    popperConfig null/object { hide: true } To change Bootstrap's default Popper config, see Popper's configuration.

    Data attributes for individual tooltips:
    Options for individual tooltips can alternatively be specified through the use of data attributes, as explained above.


    Methods

    Asynchronous methods and transitions:
    All API methods are asynchronous and start a transition. 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.

    Method Description Example
    show Reveals an element’s tooltip. Returns to the caller before the tooltip has actually been shown (i.e. before the shown.twe.tooltip event occurs). This is considered a “manual” triggering of the tooltip. tooltips whose title and content are both zero-length are never displayed. instance.show()
    hide Hides an element’s tooltip. Returns to the caller before the tooltip has actually been hidden (i.e. before the hidden.twe.tooltip event occurs). This is considered a “manual” triggering of the tooltip. instance.hide()
    toggle Toggles an element’s tooltip. Returns to the caller before the tooltip has actually been shown or hidden (i.e. before the shown.twe.tooltip or hidden.twe.tooltip event occurs). This is considered a “manual” triggering of the tooltip. instance.toggle()
    dispose Hides and destroys an element’s tooltip. tooltips that use delegation (which are created using the selector option) cannot be individually destroyed on descendant trigger elements. instance.dispose()
    enable Gives an element’s tooltip the ability to be shown. tooltips are enabled by default. instance.enable()
    disable 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. instance.disable()
    toggleEnabled Toggles the ability for an element’s tooltip to be shown or hidden. instance.toggleEnabled()
    update Updates the position of an element’s tooltip. instance.update()
    getInstance Static method which allows you to get the tooltip instance associated with a DOM element. Tooltip.getInstance()
    getOrCreateInstance Static 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. Tooltip.getOrCreateInstance()
    • javascript
    • umd
            
                
                const tooltipEl = document.getElementById('tooltip');
                const tooltip = new Tooltip(tooltipEl);
                tooltip.show();
              
            
        
            
                
                const tooltipEl = document.getElementById('tooltip');
                const tooltip = new twe.Tooltip(tooltipEl);
                tooltip.show();
              
            
        

    Events

    Event type Description
    show.twe.tooltip This event fires immediately when the show instance method is called.
    shown.twe.tooltip This event is fired when the tooltip has been made visible to the user (will wait for CSS transitions to complete).
    hide.twe.tooltip This event is fired immediately when the hide instance method has been called.
    hidden.twe.tooltip This event is fired when the tooltip has finished being hidden from the user (will wait for CSS transitions to complete).
    inserted.twe.tooltip This event is fired after the show.twe.tooltip event when the tooltip template has been added to the DOM.
    • JavaScript
            
                
                  const tooltipEl = document.getElementById('tooltip');
                  const tooltip = new twe.Tooltip(tooltipEl);
    
                  tooltipEl.addEventListener('hidden.twe.tooltip', () => {
                    // do something...
                  });
    
                  tooltip.hide();
                
            
        
    • Import
    • Usage
    • Options
    • Methods
    • Events
    Get useful tips & free resources directly to your inbox along with exclusive subscriber-only content.
    Join our mailing list now
    © 2024 Copyright: MDBootstrap.com

    Access restricted

    To view this section you must have an active PRO account

    Log in to your account or purchase an TWE subscription if you don't have one.

    Buy TWE PRO