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

    Popover

    Tailwind CSS Popover

    Use responsive placeholders component with helper examples for width, color, sizing, placeholder animations & more. Free download, open-source license.

    Required ES init: Popover *
    * 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

    Popovers are overlays that open on demand and is mainly used on elements to display more content on floating card popped by clicking or hovering.

    • HTML
    • javascript
            
                
          <button
            type="button"
            class="inline-block rounded bg-danger px-7 pb-2.5 pt-3 text-sm font-medium uppercase leading-normal text-white shadow-danger-3 transition duration-150 ease-in-out hover:bg-danger-accent-300 hover:shadow-danger-2 focus:bg-danger-accent-300 focus:shadow-danger-2 focus:outline-none focus:ring-0 active:bg-danger-600 active:shadow-danger-2 motion-reduce:transition-none dark:shadow-black/30 dark:hover:shadow-dark-strong dark:focus:shadow-dark-strong dark:active:shadow-dark-strong"
            data-twe-toggle="popover"
            data-twe-title="Popover title"
            data-twe-content="And here's some amazing content. It's very engaging. Right?"
            data-twe-ripple-init
            data-twe-ripple-color="light">
            Click to toggle popover
          </button>
          
            
        
            
                
          // Initialization for ES Users
          import {
            Popover,
            Ripple,
            initTWE,
          } from "tw-elements";
          
          initTWE({ Popover, Ripple });
          
            
        

    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

    Four options are available: top, right, bottom, and left aligned.

    • 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 motion-reduce:transition-none dark:bg-primary-300 dark:hover:bg-primary-400 dark:focus:bg-primary-400 dark:active:bg-primary-400"
            data-twe-toggle="popover"
            data-twe-placement="top"
            data-twe-content="Top popover"
            data-twe-ripple-init
            data-twe-ripple-color="light">
            Popover 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 motion-reduce:transition-none dark:bg-primary-300 dark:hover:bg-primary-400 dark:focus:bg-primary-400 dark:active:bg-primary-400"
            data-twe-toggle="popover"
            data-twe-placement="right"
            data-twe-content="Right popover"
            data-twe-ripple-init
            data-twe-ripple-color="light">
            Popover 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 motion-reduce:transition-none dark:bg-primary-300 dark:hover:bg-primary-400 dark:focus:bg-primary-400 dark:active:bg-primary-400"
            data-twe-toggle="popover"
            data-twe-placement="bottom"
            data-twe-content="Bottom popover"
            data-twe-ripple-init
            data-twe-ripple-color="light">
            Popover 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 motion-reduce:transition-none dark:bg-primary-300 dark:hover:bg-primary-400 dark:focus:bg-primary-400 dark:active:bg-primary-400"
            data-twe-toggle="popover"
            data-twe-placement="left"
            data-twe-content="Left popover"
            data-twe-ripple-init
            data-twe-ripple-color="light">
            Popover on left
          </button>
          
            
        
            
                
          // Initialization for ES Users
          import {
            Popover,
            Ripple,
            initTWE,
          } from "tw-elements";
          
          initTWE({ Popover, Ripple });
          
            
        

    Dismiss on next click

    Use the focus trigger to dismiss popovers on the user next click of a different element than the toggle element.

    Dismissible popover
    • HTML
    • javascript
            
                
          <a
            tabindex="0"
            class="inline-block rounded bg-danger px-7 pb-2.5 pt-3 text-sm font-medium uppercase leading-normal text-white shadow-danger-3 transition duration-150 ease-in-out hover:bg-danger-accent-300 hover:shadow-danger-2 focus:bg-danger-accent-300 focus:shadow-danger-2 focus:outline-none focus:ring-0 active:bg-danger-600 active:shadow-danger-2 motion-reduce:transition-none dark:shadow-black/30 dark:hover:shadow-dark-strong dark:focus:shadow-dark-strong dark:active:shadow-dark-strong"
            role="button"
            data-twe-toggle="popover"
            data-twe-trigger="focus"
            title="Dismissible popover"
            data-twe-content="And here's some amazing content. It's very engaging. Right?"
            data-twe-ripple-init
            data-twe-ripple-color="light"
            >Dismissible popover</a
          >
          
            
        
            
                
          // Initialization for ES Users
          import {
            Popover,
            Ripple,
            initTWE,
          } from "tw-elements";
          
          initTWE({ Popover, Ripple });
          
            
        

    Disabled

    Elements with the disabled attribute aren’t interactive, meaning users cannot hover or click them to trigger a popover.

    • HTML
    • javascript
            
                
          <span
            class="inline-block focus:outline-none"
            tabindex="0"
            data-twe-toggle="popover"
            data-twe-trigger="hover focus"
            data-twe-content="Disabled popover">
            <button
              class="pointer-events-none rounded bg-primary px-6 pb-2 pt-2.5 text-xs font-medium uppercase leading-normal text-white opacity-60 shadow-primary-3 transition duration-150 ease-in-out hover:bg-primary-accent-300 hover:shadow-primary-2 focus:bg-primary-accent-300 focus:shadow-primary-2 focus:outline-0 focus:ring-0 active:bg-primary-600 active:shadow-primary-2 dark:shadow-black/30 dark:hover:shadow-dark-strong dark:focus:shadow-dark-strong dark:active:shadow-dark-strong"
              type="button"
              disabled>
              Disabled button
            </button>
          </span>
          
            
        
            
                
          // Initialization for ES Users
          import {
            Popover,
            Ripple,
            initTWE,
          } from "tw-elements";
          
          initTWE({ Popover, Ripple });
          
            
        

    Related resources

    Tutorials:

    hover state dark mode buttons ripple effect rounded corners shadows sizing

    Extended Docs:

    animations colors hover effects images alerts badges buttons collapse dropdown modal notifications social buttons tooltip charts box sizing center text colors dark theme 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
    • Dismiss on next click
    • Disabled
    • Related resources

    Popover - 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 { Popover, initTWE } from "tw-elements";
            initTWE({ Popover });
            
            
        
            
                
            import "tw-elements";
            
            
        

    Usage

    Via data attributes

    • HTML
            
                
            <button
              type="button"
              class="inline-block rounded bg-danger px-7 pb-2.5 pt-3 text-sm font-medium uppercase leading-normal text-white shadow-danger-3 transition duration-150 ease-in-out hover:bg-danger-accent-300 hover:shadow-danger-2 focus:bg-danger-accent-300 focus:shadow-danger-2 focus:outline-none focus:ring-0 active:bg-danger-600 active:shadow-danger-2 dark:shadow-black/30 dark:hover:shadow-dark-strong dark:focus:shadow-dark-strong dark:active:shadow-dark-strong"
              data-twe-toggle="popover"
              data-twe-title="Popover title"
              data-twe-content="And here's some amazing content. It's very engaging. Right?">
              Click to toggle popover
            </button>
            
            
        

    Via JavaScript

    • javascript
    • umd
            
                
              const exampleEl = document.getElementById('example');
              const popover = new Popover(exampleEl, options);
            
            
        
            
                
              const exampleEl = document.getElementById('example');
              const popover = new twe.Popover(exampleEl, options);
            
            
        

    Making popovers work for keyboard and assistive technology users

    To allow keyboard users to activate your popovers, you should only add them 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 popover’s content in this situation. Additionally, do not rely solely on hover as the trigger for your popovers, as this will make them impossible to trigger for keyboard users.

    While you can insert rich, structured HTML in popovers with the html option, we strongly recommend that you avoid adding an excessive amount of content. The way popovers currently work is that, once displayed, their content is tied to the trigger element with the aria-describedby attribute. As a result, the entirety of the popover’s content will be announced to assistive technology users as one long, uninterrupted stream.

    Additionally, while it is possible to also include interactive controls (such as form elements or links) in your popover (by adding these elements to the allowList or allowed attributes and tags), be aware that currently the popover does not manage keyboard focus order. When a keyboard user opens a popover, focus remains on the triggering element, and as the popover usually does not immediately follow the trigger in the document’s structure, there is no guarantee that moving forward/pressing TAB will move a keyboard user into the popover itself. In short, simply adding interactive controls to a popover is likely to make these controls unreachable/unusable for keyboard users and users of assistive technologies, or at the very least make for an illogical overall focus order. In these cases, consider using a modal dialog instead.


    Options

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

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

    Name Type Default Description
    container string/element/boolean false Appends the popover to a specific element. Example: container: 'body'. This option is particularly useful in that it allows you to position the popover in the flow of the document near the triggering element - which will prevent the popover from floating away from the triggering element during a window resize.
    content string/element/function - Default content value if data-twe-content attribute isn't present. If a function is given, it will be called with its this reference set to the element that the popover is attached to.
    html boolean false Insert HTML into the popover. 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 popover - auto | top | bottom | left | right. When auto is specified, it will dynamically reorient the popover. When a function is used to determine the placement, it is called with the popover DOM node as its first argument and the triggering element DOM node as its second. The this context is set to the popover instance.
    selector string/boolean false If a selector is provided, popover objects will be delegated to the specified targets. In practice, this is used to enable dynamic HTML content to have popovers added. See this and an informative example.
    template string ` <div class="opacity-0 transition-opacity duration-150 ease-in-out absolute top-0 left-0 z-[1070] block max-w-[267px] break-words bg-white bg-clip-padding border border-neutral-100 rounded-lg shadow-2 text-sm not-italic font-normal text-left no-underline underline-offset-auto normal-case leading-6 tracking-normal break-normal whitespace-normal dark:border-white/10 dark:bg-surface-dark dark:text-white data-[popper-reference-hidden]:hidden" role="tooltip"> <h3 data-twe-popover-header-ref class="py-2 px-4 mb-0 border-b-2 border-neutral-100 rounded-t-lg font-medium empty:hidden dark:border-white/10"></h3> <div data-twe-popover-body-ref class="p-4 text-surface dark:text-white"></div> </div> ` Base HTML to use when creating the popover. The popover's title will be injected into the .popover-header. The popover's content will be injected into the .popover-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 popover is attached to.
    trigger string 'click' How popover is triggered - click | hover | focus | manual. You may pass multiple triggers; separate them with a space. manual cannot be combined with any other trigger.
    offset number/string 0 Offset of the popover 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 popover (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.
    allowList 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 popovers:
    Options for individual popovers 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 popover. Returns to the caller before the popover has actually been shown (i.e. before the shown.twe.popover event occurs). This is considered a “manual” triggering of the popover. Popovers whose title and content are both zero-length are never displayed. myPopover.show()
    hide Hides an element’s popover. Returns to the caller before the popover has actually been hidden (i.e. before the hidden.twe.popover event occurs). This is considered a “manual” triggering of the popover. myPopover.hide()
    toggle Toggles an element’s popover. Returns to the caller before the popover has actually been shown or hidden (i.e. before the shown.twe.popover or hidden.twe.popover event occurs). This is considered a “manual” triggering of the popover. myPopover.toggle()
    dispose Hides and destroys an element’s popover. Popovers that use delegation (which are created using the selector option) cannot be individually destroyed on descendant trigger elements. myPopover.dispose()
    enable Gives an element’s popover the ability to be shown. Popovers are enabled by default. myPopover.enable()
    disable Removes the ability for an element’s popover to be shown. The popover will only be able to be shown if it is re-enabled. myPopover.disable()
    toggleEnabled Toggles the ability for an element’s popover to be shown or hidden. myPopover.toggleEnabled()
    update Updates the position of an element’s popover. myPopover.update({delay: { "show": 500, "hide": 100 }})
    getInstance Static method which allows you to get the popover instance associated with a DOM element. Popover.getInstance()
    getOrCreateInstance Static method which allows you to get the popover instance associated with a DOM element or create a new one in case it wasn't initialized. Popover.getOrCreateInstance()
    • javascript
    • umd
            
                
                const exampleTriggerEl = document.getElementById('example');
                const popover = new Popover(exampleTriggerEl);
                popover.show();
              
            
        
            
                
                const exampleTriggerEl = document.getElementById('example');
                const popover = new twe.Popover(exampleTriggerEl);
                popover.show();
              
            
        

    Events

    Event type Description
    show.twe.popover This event fires immediately when the show instance method is called.
    shown.twe.popover This event is fired when the popover has been made visible to the user (will wait for CSS transitions to complete).
    hide.twe.popover This event is fired immediately when the hide instance method has been called.
    hidden.twe.popover This event is fired when the popover has finished being hidden from the user (will wait for CSS transitions to complete).
    inserted.twe.popover This event is fired after the show.twe.popover event when the popover template has been added to the DOM.
    • JavaScript
            
                
                  const myPopoverTrigger = document.getElementById('myPopover')
                  myPopoverTrigger.addEventListener('hidden.twe.popover', () => {
                    // do something...
                  });
                
            
        
    • 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