Tailwind CSS Tooltip

Customise your web projects with an easy-to-use and responsive Tailwind CSS tooltip!

A tooltip is a small pop-up element that appears while the user moves the mouse pointer over an element. Use it when you want to specify extra information about something when the user moves the mouse pointer over an element.

See below our example that will help you create a simple tooltip for your project.


You can initialize a new tooltip by adding the data-tooltip-target="{tooltipName}" data attribute to the trigger element and the data-tooltip="{tooltipName}" to the element that you want to use as the tooltip.

Material Tailwind

Tooltip Placement

You can change the position of the tooltip relative to it's trigger element by adding the data-tooltip-placement="{top}" data attribute to the tooltip element by default it set's to top.
Check the placement values for tooltip here.

Material Tailwind
Material Tailwind
Material Tailwind
Material Tailwind
Material Tailwind
Material Tailwind
Material Tailwind
Material Tailwind
Material Tailwind
Material Tailwind
Material Tailwind
Material Tailwind

Custom Tooltip Animation

You can modify the open/close state animation for tooltip by adding the data-tooltip-mount="{opacity-100}", data-tooltip-unmount="{opacity-0}" and data-tooltip-transition="{transition-opacity}" data attributes to the tooltip element. You can pass tailwind css classnames for those data attributes for animation the tooltip.
Check more about animation data attributes for tooltip here.

Material Tailwind

Tooltip Trigger Data Attributes

The following data attributes are available for tooltip trigger element.

AttributeDescription
data-tooltip-targetSet the tooltip target element, it should be the same as the data-tooltip data attribute.

Tooltip Data Attributes

The following data attributes are available for tooltip element.

AttributeDescriptionDefault
data-tooltipSet the name of the tooltip and reference it to the
tooltip trigger element.
data-tooltip-offsetSet the offset between the tooltip and the tooltip trigger element.5
data-tooltip-placementSet the position of the tooltip relative to it's trigger element.top
data-tooltip-mountSet the classnaes that should be used when the
tooltip is visible.
opacity-1
data-tooltip-unmountSet the classnaes that should be used when the
tooltip is hidden.
opacity-0
pointer-events-none
data-tooltip-transitionSet the classnaes that should be used for
transition of the tooltip.
transition-opacity
duration-300

Required Scrips

The tooltip component needs a required script file to work, you just need to add the below script file to the bottom of your html file.

<!-- from node_modules -->
<script
  type="module"
  src="node_modules/@material-tailwind/html@latest/scripts/tooltip.js"
></script>
 
<!-- from cdn -->
<script
  type="module"
  src="https://unpkg.com/@material-tailwind/html@latest/scripts/tooltip.js"
></script>
Edit this page on Github