Socket
Book a DemoInstallSign in
Socket

headless-tooltip

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

headless-tooltip

A minimal, accessible, and unstyled tooltip component for React

1.0.0
latest
Source
npmnpm
Version published
Weekly downloads
467
-20.98%
Maintainers
1
Weekly downloads
 
Created
Source

headless-tooltip

npm version npm downloads bundle size minified license TypeScript PRs Welcome

A lightweight, customizable tooltip component for React with zero styling opinions. Built with accessibility in mind.

If you find Headless-Tooltip useful, please consider giving it a ⭐

Features

  • 🎨 Truly headless: No predefined styles, full control over tooltip appearance
  • Accessible: Follows WAI-ARIA Tooltip Pattern
  • 🧩 Flexible: Supports custom content, including HTML and React components
  • 📱 Responsive: Automatically adapts to different screen sizes
  • 🔄 Interactive mode: Optional interactive tooltips that remain visible when hovering
  • 🏹 Customizable arrow: Optional arrow that can be styled and positioned
  • 🌐 Placement options: 12 different placement positions for tooltip
  • ⌨️ Keyboard friendly: Fully keyboard accessible with proper focus management

Installation

npm

npm install headless-tooltip

yarn

yarn add headless-tooltip

pnpm

pnpm add headless-tooltip

Basic Usage

import Tooltip from 'headless-tooltip';

function Example() {
  return (
    <Tooltip content="This is a tooltip message">
      <button>Hover me</button>
    </Tooltip>
  );
}

Styled Example

import Tooltip from 'headless-tooltip';

function StyledExample() {
  return (
    <Tooltip
      content={<span>This is a tooltip message</span>}
      placement="bottom"
      arrow={true}
      className="max-w-80 rounded-lg bg-gray-900 px-3 py-2 text-xs font-normal text-white"
      arrowClassName="bg-gray-900"
    >
      <button className="px-4 py-2 bg-blue-500 text-white rounded">
        Hover me
      </button>
    </Tooltip>
  );
}

API Reference

Props

PropTypeDefaultDescription
childrenReact.ReactNode(required)The element that triggers the tooltip
contentReact.ReactNode(required)The content to be displayed in the tooltip
placementPositionType'top'Tooltip placement relative to the trigger element
classNamestring''Additional CSS classes to apply to the tooltip
offsetnumber4Distance between tooltip and trigger element in pixels
zIndexnumberundefinedZ-index value for the tooltip
openbooleanundefinedControl tooltip visibility (makes it a controlled component)
openDelaynumber300Delay in ms before showing the tooltip
closeDelaynumber200Delay in ms before hiding the tooltip
disableInteractivebooleanfalseIf true, tooltip will close when mouse leaves trigger
onOpenChange(open: boolean) => voidundefinedCallback when tooltip visibility changes
portalContainerHTMLElementdocument.bodyDOM element where tooltip portal will be rendered
arrowbooleanfalseWhether to show an arrow pointing to the trigger
arrowSizenumber12Size of the arrow in pixels
arrowClassNamestringundefinedAdditional CSS classes to apply to the arrow

Placement Types

The placement prop accepts the following values:

  • 'top'
  • 'right'
  • 'bottom'
  • 'left'
  • 'top-start'
  • 'top-end'
  • 'right-start'
  • 'right-end'
  • 'bottom-start'
  • 'bottom-end'
  • 'left-start'
  • 'left-end'

Accessibility

This tooltip implementation follows the WAI-ARIA Tooltip Pattern to ensure accessibility compliance:

  • Uses appropriate ARIA attributes (role="tooltip", aria-describedby)
  • Supports keyboard navigation with proper focus management
  • Dismissible with Escape key
  • Works with screen readers
  • Triggered by both hover and focus events

Browser Support

The component is compatible with all modern browsers:

  • Chrome (and Chromium-based browsers)
  • Firefox
  • Safari
  • Edge

Advanced Usage

Controlled Mode

import { useState } from 'react';
import Tooltip from 'headless-tooltip';

function ControlledExample() {
  const [isOpen, setIsOpen] = useState(false);

  return (
    <div>
      <button onClick={() => setIsOpen(!isOpen)}>Toggle Tooltip</button>

      <Tooltip
        content="This is a controlled tooltip"
        open={isOpen}
        onOpenChange={setIsOpen}
      >
        <button>Hover me too</button>
      </Tooltip>
    </div>
  );
}

Interactive Tooltip

import Tooltip from 'headless-tooltip';

function InteractiveExample() {
  return (
    <Tooltip
      content={
        <div>
          <p>Interactive tooltip with a button:</p>
          <button onClick={() => alert('Clicked!')}>Click me</button>
        </div>
      }
      disableInteractive={false}
    >
      <button>Hover for interactive tooltip</button>
    </Tooltip>
  );
}

Contributing

Contributions are always welcome! Please feel free to submit a Pull Request.

License

MIT

Keywords

tooltip

FAQs

Package last updated on 12 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.