Skip to content

ComponentsFeedback

SourceSource

Tooltip

A Discord-inspired floating label with an arrow that points at its element, shown on hover or keyboard focus.

A hover bubble built on Radix Tooltip in React and Reka UI Tooltip in Vue. It is a hint, never the only place information lives — a control whose meaning is only in its tooltip is a control with no accessible name.

The bubble is a floating surface with a thin edge and the high elevation shadow, the same as a select menu or a modal. An arrow on the edge that faces the trigger points at it. A short label stays on one line; a longer one wraps at 200px. It fades in and grows from 95% out of the side that faces the trigger, and opens as soon as the pointer reaches the trigger.

Root class newt-tooltip
import {
  Tooltip,
  TooltipContent,
  TooltipTrigger,
} from "@/registry/bases/newt/ui/tooltip"

export default function TooltipDemo() {
  return (
    <Tooltip>
      <TooltipTrigger asChild>
        <button
          type="button"
          aria-label="Help"
          className="inline-flex h-8 w-8 items-center justify-center rounded-full bg-newt-bg-elevated text-sm font-medium text-newt-text-secondary transition-colors duration-fast ease-newt hover:bg-newt-bg-hover hover:text-newt-text-primary"
        >
          ?
        </button>
      </TooltipTrigger>
      <TooltipContent>Tooltip text</TooltipContent>
    </Tooltip>
  )
}
<script setup lang="ts">
import {
  Tooltip,
  TooltipContent,
  TooltipTrigger,
} from "~~/registry/bases/newt/ui/tooltip"
</script>

<template>
  <Tooltip>
    <TooltipTrigger as-child>
      <button
        type="button"
        aria-label="Help"
        class="inline-flex h-8 w-8 items-center justify-center rounded-full bg-newt-bg-elevated text-sm font-medium text-newt-text-secondary transition-colors duration-fast ease-newt hover:bg-newt-bg-hover hover:text-newt-text-primary"
      >
        ?
      </button>
    </TooltipTrigger>
    <TooltipContent>Tooltip text</TooltipContent>
  </Tooltip>
</template>

Installation

npx newtui@latest add tooltipnpx shadcn@latest add @newtui/tooltipnpx shadcn-vue@latest add @newtui/tooltippnpm dlx newtui@latest add tooltippnpm dlx shadcn@latest add @newtui/tooltippnpm dlx shadcn-vue@latest add @newtui/tooltipyarn dlx newtui@latest add tooltipyarn dlx shadcn@latest add @newtui/tooltipyarn dlx shadcn-vue@latest add @newtui/tooltipbunx newtui@latest add tooltipbunx shadcn@latest add @newtui/tooltipbunx shadcn-vue@latest add @newtui/tooltipdeno run -A npm:newtui@latest add tooltipdeno run -A npm:shadcn@latest add @newtui/tooltipdeno run -A npm:shadcn-vue@latest add @newtui/tooltipvlx newtui@latest add tooltipvlx shadcn@latest add @newtui/tooltipvlx shadcn-vue@latest add @newtui/tooltipvp dlx newtui@latest add tooltipvp dlx shadcn@latest add @newtui/tooltipvp dlx shadcn-vue@latest add @newtui/tooltipnubx newtui@latest add tooltipnubx shadcn@latest add @newtui/tooltipnubx shadcn-vue@latest add @newtui/tooltipnlx newtui@latest add tooltipnlx shadcn@latest add @newtui/tooltipnlx shadcn-vue@latest add @newtui/tooltipupx newtui@latest add tooltipupx shadcn@latest add @newtui/tooltipupx shadcn-vue@latest add @newtui/tooltip

The shadcn CLI needs the @newtui registry in your components.json. Set it up.

Install the dependencies

npm install radix-uipnpm add radix-uiyarn add radix-uibun add radix-uideno add npm:radix-uivlt install radix-uivp add radix-uinub add radix-uini radix-uiupm add radix-ui
npm install reka-uipnpm add reka-uiyarn add reka-uibun add reka-uideno add npm:reka-uivlt install reka-uivp add reka-uinub add reka-uini reka-uiupm add reka-ui

Copy the source into your project

"use client"

import { Tooltip as TooltipPrimitive } from "radix-ui"
import * as React from "react"

import { cn } from "@/lib/utils"

/*
 * Radix owns the behaviour: the hover delay, opening at once on keyboard
 * focus, Escape to dismiss, and collision-aware placement. Only the look is
 * newt/ui's.
 */

/* True below a `TooltipProvider`, so a tooltip knows it can share that one. */
const SharedProviderContext = React.createContext(false)

type TooltipProviderProps = Omit<
  React.ComponentProps<typeof TooltipPrimitive.Provider>,
  "delayDuration"
> & {
  /**
   * Milliseconds the pointer rests on a trigger before its tooltip opens.
   * Keyboard focus opens it at once.
   * @default 0
   */
  delay?: number
}

/*
 * Optional. Wrap a group of tooltips in one provider and they share its
 * delays: after one closes, its neighbour opens with no wait. The provider
 * holds the one default for `delay`; a lone `Tooltip` brings its own.
 */
function TooltipProvider({ delay = 0, ...props }: TooltipProviderProps) {
  return (
    <SharedProviderContext.Provider value={true}>
      <TooltipPrimitive.Provider delayDuration={delay} {...props} />
    </SharedProviderContext.Provider>
  )
}

type TooltipProps = Omit<
  React.ComponentProps<typeof TooltipPrimitive.Root>,
  "delayDuration"
> & {
  /**
   * Milliseconds the pointer rests on the trigger before it opens. Overrides
   * the provider's `delay` for this tooltip.
   */
  delay?: number
}

/* A tooltip with no `TooltipProvider` above it brings its own. */
function Tooltip({ delay, ...props }: TooltipProps) {
  const shared = React.useContext(SharedProviderContext)
  if (shared) {
    return <TooltipPrimitive.Root delayDuration={delay} {...props} />
  }
  return (
    <TooltipProvider delay={delay}>
      <TooltipPrimitive.Root {...props} />
    </TooltipProvider>
  )
}

const TooltipTrigger = TooltipPrimitive.Trigger

/*
 * The edge is an inset shadow, not a border: a border would shift the arrow
 * off the trigger's centre, because Radix places it inside the border.
 * Radix keeps the bubble mounted until its close animation ends. It grows out
 * of the side that faces the trigger; `scale` leaves `transform` to the
 * positioning wrapper. Reduced motion turns both animations off.
 */
const contentClassName =
  "z-[120] box-border w-max max-w-[200px] break-words rounded-[var(--newt-radius-md)] bg-newt-bg-floating px-[var(--newt-space-3)] py-[var(--newt-space-2)] text-center text-[length:var(--newt-font-size-xs)] font-[number:var(--newt-font-weight-medium)] leading-[16px] text-newt-text-primary shadow-[inset_0_0_0_1px_var(--newt-border-subtle),var(--newt-shadow-elevation-high)] origin-[var(--radix-tooltip-content-transform-origin)] data-[state=delayed-open]:animate-[newt-tooltip-in_var(--newt-duration-fast)_var(--newt-ease-out)] data-[state=instant-open]:animate-[newt-tooltip-in_var(--newt-duration-fast)_var(--newt-ease-out)] data-[state=closed]:animate-[newt-tooltip-out_var(--newt-duration-fast)_var(--newt-ease-out)] motion-reduce:data-[state=delayed-open]:animate-none motion-reduce:data-[state=instant-open]:animate-none motion-reduce:data-[state=closed]:animate-none"

const keyframes = `
@keyframes newt-tooltip-in { from { opacity: 0; scale: 0.95; } }
@keyframes newt-tooltip-out { to { opacity: 0; scale: 0.95; } }`

/*
 * The arrow points down; Radix turns it to face the trigger on whichever side
 * the bubble ends up. It is the edge colour over the surface, then the
 * surface 1px further in. Moved 1px into the bubble, it covers the bubble's
 * edge where they meet, so the two read as one shape.
 *
 * The keyframes ride in the arrow, which is hidden from assistive technology,
 * so the rules never join the description the trigger points at.
 */
function TooltipArrow() {
  return (
    <TooltipPrimitive.Arrow asChild width={16} height={8}>
      <svg
        viewBox="0 0 16 8"
        aria-hidden="true"
        className="block -translate-y-px overflow-visible"
      >
        <style>{keyframes}</style>
        <path
          className="fill-newt-bg-floating"
          d="M0 1H16L9.4 7.6Q8 9 6.6 7.6Z"
        />
        <path
          className="fill-newt-border-subtle"
          d="M0 1H16L9.4 7.6Q8 9 6.6 7.6Z"
        />
        <path
          className="fill-newt-bg-floating"
          d="M0 0H16L9.4 6.6Q8 8 6.6 6.6Z"
        />
      </svg>
    </TooltipPrimitive.Arrow>
  )
}

/*
 * No `asChild`: the content holds the label and the arrow, and Radix merges
 * `asChild` onto a single child only.
 */
type TooltipContentProps = Omit<
  React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content>,
  "asChild"
> & {
  /**
   * The element the tooltip is portalled into. Defaults to `document.body`;
   * pass the enclosing native `<dialog>` or a themed wrapper to keep it there.
   */
  container?: React.ComponentProps<typeof TooltipPrimitive.Portal>["container"]
}

/*
 * `sideOffset` is the gap between the trigger and the arrow tip. At 0 the
 * bubble sits 8px, the arrow's height, from the trigger.
 */
const TooltipContent = React.forwardRef<
  React.ComponentRef<typeof TooltipPrimitive.Content>,
  TooltipContentProps
>(({ className, children, sideOffset = 0, container, ...props }, ref) => (
  <TooltipPrimitive.Portal container={container}>
    <TooltipPrimitive.Content
      ref={ref}
      sideOffset={sideOffset}
      className={cn(contentClassName, className)}
      {...props}
    >
      {children}
      <TooltipArrow />
    </TooltipPrimitive.Content>
  </TooltipPrimitive.Portal>
))
TooltipContent.displayName = "TooltipContent"

export { Tooltip, TooltipProvider, TooltipTrigger, TooltipContent }
export type { TooltipProps, TooltipProviderProps, TooltipContentProps }
<script setup lang="ts">
import {
  injectTooltipProviderContext,
  TooltipRoot,
  useForwardPropsEmits,
  type TooltipRootEmits,
  type TooltipRootProps,
} from "reka-ui"
import { computed } from "vue"

import TooltipProvider from "./TooltipProvider.vue"

const props = defineProps<
  Omit<TooltipRootProps, "delayDuration"> & {
    /**
     * Milliseconds the pointer rests on the trigger before it opens.
     * Overrides the provider's `delay` for this tooltip.
     */
    delay?: number
  }
>()
const emits = defineEmits<TooltipRootEmits>()

/* Only the props the caller set reach Reka, so its own defaults still apply. */
const delegated = computed(() => {
  const { delay: _delay, ...rest } = props
  return rest
})
const forwarded = useForwardPropsEmits(delegated, emits)

/* A tooltip with no `TooltipProvider` above it brings its own. */
const shared = injectTooltipProviderContext(null)
</script>

<template>
  <TooltipRoot v-if="shared" v-bind="forwarded" :delay-duration="props.delay">
    <slot />
  </TooltipRoot>
  <TooltipProvider v-else :delay="props.delay">
    <TooltipRoot v-bind="forwarded">
      <slot />
    </TooltipRoot>
  </TooltipProvider>
</template>
<script setup lang="ts">
import { TooltipProvider, type TooltipProviderProps } from "reka-ui"

/*
 * Optional. Wrap a group of tooltips in one provider and they share its
 * delays: after one closes, its neighbour opens with no wait. The provider
 * holds the one default for `delay`; a lone `Tooltip` brings its own.
 */
const { delay = 0, ...rest } = defineProps<
  Omit<TooltipProviderProps, "delayDuration"> & {
    /**
     * Milliseconds the pointer rests on a trigger before its tooltip opens.
     * Keyboard focus opens it at once.
     */
    delay?: number
  }
>()
</script>

<template>
  <TooltipProvider v-bind="rest" :delay-duration="delay">
    <slot />
  </TooltipProvider>
</template>
<script setup lang="ts">
import { TooltipTrigger, type TooltipTriggerProps } from "reka-ui"

const props = defineProps<TooltipTriggerProps>()
</script>

<template>
  <TooltipTrigger v-bind="props">
    <slot />
  </TooltipTrigger>
</template>
<script setup lang="ts">
import {
  TooltipArrow,
  TooltipContent,
  TooltipPortal,
  useForwardPropsEmits,
  type TooltipContentEmits,
  type TooltipContentProps,
} from "reka-ui"
import { computed, type HTMLAttributes } from "vue"

import { cn } from "@/lib/utils"

defineOptions({ inheritAttrs: false })

/*
 * `sideOffset` is the gap between the trigger and the arrow tip. At 0 the
 * bubble sits 8px, the arrow's height, from the trigger.
 */
const props = withDefaults(
  /*
   * No `asChild`: the content holds the label and the arrow, and a slot
   * merges onto a single child only.
   */
  defineProps<
    Omit<TooltipContentProps, "asChild"> & {
      class?: HTMLAttributes["class"]
      /**
       * The element it is portalled into. Defaults to `body`; pass the
       * enclosing native `<dialog>` or a themed wrapper to keep it there.
       */
      container?: string | HTMLElement
    }
  >(),
  { sideOffset: 0 }
)
const emits = defineEmits<TooltipContentEmits>()

const delegated = computed(() => {
  const { class: _class, container: _container, ...rest } = props
  return rest
})
const forwarded = useForwardPropsEmits(delegated, emits)
</script>

<template>
  <TooltipPortal :to="props.container">
    <!--
      The edge is an inset shadow, not a border: a border would shift the
      arrow off the trigger's centre, because Reka places it inside the
      border. Reka keeps the bubble mounted until its close animation ends. It grows
      out of the side that faces the trigger; `scale` leaves `transform` to
      the positioning wrapper. Reduced motion turns both animations off.
    -->
    <TooltipContent
      v-bind="{ ...forwarded, ...$attrs }"
      :class="
        cn(
          'z-[120] box-border w-max max-w-[200px] break-words rounded-[var(--newt-radius-md)] bg-newt-bg-floating px-[var(--newt-space-3)] py-[var(--newt-space-2)] text-center text-[length:var(--newt-font-size-xs)] font-[number:var(--newt-font-weight-medium)] leading-[16px] text-newt-text-primary shadow-[inset_0_0_0_1px_var(--newt-border-subtle),var(--newt-shadow-elevation-high)] origin-[var(--reka-tooltip-content-transform-origin)] data-[state=delayed-open]:animate-[newt-tooltip-in_var(--newt-duration-fast)_var(--newt-ease-out)] data-[state=instant-open]:animate-[newt-tooltip-in_var(--newt-duration-fast)_var(--newt-ease-out)] data-[state=closed]:animate-[newt-tooltip-out_var(--newt-duration-fast)_var(--newt-ease-out)] motion-reduce:data-[state=delayed-open]:animate-none motion-reduce:data-[state=instant-open]:animate-none motion-reduce:data-[state=closed]:animate-none',
          props.class
        )
      "
    >
      <slot />
      <!--
        The arrow points down; Reka turns it to face the trigger on whichever
        side the bubble ends up. It is the edge colour over the surface, then
        the surface 1px further in. Moved 1px into the bubble, it covers the
        bubble's edge where they meet, so the two read as one shape.
      -->
      <TooltipArrow as-child :width="16" :height="8">
        <svg
          viewBox="0 0 16 8"
          aria-hidden="true"
          class="block -translate-y-px overflow-visible"
        >
          <path
            class="fill-newt-bg-floating"
            d="M0 1H16L9.4 7.6Q8 9 6.6 7.6Z"
          />
          <path
            class="fill-newt-border-subtle"
            d="M0 1H16L9.4 7.6Q8 9 6.6 7.6Z"
          />
          <path
            class="fill-newt-bg-floating"
            d="M0 0H16L9.4 6.6Q8 8 6.6 6.6Z"
          />
        </svg>
      </TooltipArrow>
    </TooltipContent>
  </TooltipPortal>
</template>

<style>
@keyframes newt-tooltip-in {
  from {
    opacity: 0;
    scale: 0.95;
  }
}
@keyframes newt-tooltip-out {
  to {
    opacity: 0;
    scale: 0.95;
  }
}
</style>
export { default as Tooltip } from "./Tooltip.vue"
export { default as TooltipTrigger } from "./TooltipTrigger.vue"
export { default as TooltipContent } from "./TooltipContent.vue"
export { default as TooltipProvider } from "./TooltipProvider.vue"

Update the import paths

The files import @/lib/utils and sibling components through the aliases in your components.json. Point them at wherever those live in your project.

No CLI, no components.json: paste this into Claude, Cursor, Copilot or any coding assistant and it adds Tooltip to your React project by hand. The prompt carries the source of every file the CLI would write — this component's and those of the components it builds on — with the imports already pointed at the default aliases.

No CLI, no components.json: paste this into Claude, Cursor, Copilot or any coding assistant and it adds Tooltip to your Vue project by hand. The prompt carries the source of every file the CLI would write — this component's and those of the components it builds on — with the imports already pointed at the default aliases.

Usage

import { Tooltip } from "@/components/ui/tooltip"

export function Example() {
  return <Tooltip />
}
<script setup lang="ts">
import { Tooltip, TooltipProvider, TooltipTrigger, TooltipContent } from "@/components/ui/tooltip"
</script>

<template>
  <Tooltip />
</template>

Examples

Icon buttons

The usual place for a tooltip: a button that shows only an icon. Give the button an aria-label with the same words, so the label a sighted reader sees on hover is also the name a screen reader announces. Use asChild (as-child in Vue) on TooltipTrigger to put the tooltip on your own button.

Root class newt-tooltip
import {
  Tooltip,
  TooltipContent,
  TooltipProvider,
  TooltipTrigger,
} from "@/registry/bases/newt/ui/tooltip"

const ACTIONS = [
  {
    label: "Mute",
    icon: "M12 3a3 3 0 0 0-3 3v5a3 3 0 0 0 6 0V6a3 3 0 0 0-3-3ZM6 11a6 6 0 0 0 12 0M12 17v4",
  },
  {
    label: "Deafen",
    icon: "M4 14v-2a8 8 0 0 1 16 0v2M4 14h3v6H5a1 1 0 0 1-1-1v-5ZM20 14h-3v6h2a1 1 0 0 0 1-1v-5Z",
  },
  {
    label: "Voice settings",
    icon: "M4 7h10M18 7h2M14 7a2 2 0 1 0 4 0a2 2 0 1 0-4 0M4 17h2M10 17h10M6 17a2 2 0 1 0 4 0a2 2 0 1 0-4 0",
  },
]

/*
 * An icon-only button has no text of its own, so `aria-label` names it and
 * the tooltip shows the same words to sighted users. One `TooltipProvider`
 * around the group gives every tooltip in it the same `delay`, set once.
 */
export default function TooltipToolbarDemo() {
  return (
    <TooltipProvider>
      <div className="flex gap-1 rounded-md bg-newt-bg-base p-1">
        {ACTIONS.map((action) => (
          <Tooltip key={action.label}>
            <TooltipTrigger asChild>
              <button
                type="button"
                aria-label={action.label}
                className="inline-flex h-8 w-8 cursor-pointer items-center justify-center rounded-sm border-0 bg-transparent text-newt-text-secondary transition-colors duration-fast ease-newt hover:bg-newt-bg-hover hover:text-newt-text-primary"
              >
                <svg viewBox="0 0 24 24" aria-hidden="true" className="h-5 w-5">
                  <path
                    fill="none"
                    stroke="currentColor"
                    strokeWidth="2"
                    strokeLinecap="round"
                    strokeLinejoin="round"
                    d={action.icon}
                  />
                </svg>
              </button>
            </TooltipTrigger>
            <TooltipContent>{action.label}</TooltipContent>
          </Tooltip>
        ))}
      </div>
    </TooltipProvider>
  )
}
<script setup lang="ts">
import {
  Tooltip,
  TooltipContent,
  TooltipProvider,
  TooltipTrigger,
} from "~~/registry/bases/newt/ui/tooltip"

/*
 * An icon-only button has no text of its own, so `aria-label` names it and
 * the tooltip shows the same words to sighted users. One `TooltipProvider`
 * around the group gives every tooltip in it the same `delay`, set once.
 */
const actions = [
  {
    label: "Mute",
    icon: "M12 3a3 3 0 0 0-3 3v5a3 3 0 0 0 6 0V6a3 3 0 0 0-3-3ZM6 11a6 6 0 0 0 12 0M12 17v4",
  },
  {
    label: "Deafen",
    icon: "M4 14v-2a8 8 0 0 1 16 0v2M4 14h3v6H5a1 1 0 0 1-1-1v-5ZM20 14h-3v6h2a1 1 0 0 0 1-1v-5Z",
  },
  {
    label: "Voice settings",
    icon: "M4 7h10M18 7h2M14 7a2 2 0 1 0 4 0a2 2 0 1 0-4 0M4 17h2M10 17h10M6 17a2 2 0 1 0 4 0a2 2 0 1 0-4 0",
  },
]
</script>

<template>
  <TooltipProvider>
    <div class="flex gap-1 rounded-md bg-newt-bg-base p-1">
      <Tooltip v-for="action in actions" :key="action.label">
        <TooltipTrigger as-child>
          <button
            type="button"
            :aria-label="action.label"
            class="inline-flex h-8 w-8 cursor-pointer items-center justify-center rounded-sm border-0 bg-transparent text-newt-text-secondary transition-colors duration-fast ease-newt hover:bg-newt-bg-hover hover:text-newt-text-primary"
          >
            <svg viewBox="0 0 24 24" aria-hidden="true" class="h-5 w-5">
              <path
                fill="none"
                stroke="currentColor"
                stroke-width="2"
                stroke-linecap="round"
                stroke-linejoin="round"
                :d="action.icon"
              />
            </svg>
          </button>
        </TooltipTrigger>
        <TooltipContent>{{ action.label }}</TooltipContent>
      </Tooltip>
    </div>
  </TooltipProvider>
</template>

With a shortcut

TooltipContent is a slot. Add Kbd after the label to teach the keys that do the same thing. It takes no asChild (as-child in Vue): it holds both your label and the arrow, so there is no single child to merge onto.

Root class newt-tooltip
import { Button } from "@/registry/bases/newt/ui/button"
import { Kbd } from "@/registry/bases/newt/ui/kbd-tag"
import {
  Tooltip,
  TooltipContent,
  TooltipTrigger,
} from "@/registry/bases/newt/ui/tooltip"

/* The content is a slot: the label can bring the keys that do the same thing. */
export default function TooltipShortcutDemo() {
  return (
    <Tooltip>
      <TooltipTrigger asChild>
        <Button variant="secondary">Quick switcher</Button>
      </TooltipTrigger>
      <TooltipContent className="flex items-center gap-1.5">
        Jump to a channel
        <Kbd>Ctrl</Kbd>
        <Kbd>K</Kbd>
      </TooltipContent>
    </Tooltip>
  )
}
<script setup lang="ts">
import { Button } from "~~/registry/bases/newt/ui/button"
import { Kbd } from "~~/registry/bases/newt/ui/kbd-tag"
import {
  Tooltip,
  TooltipContent,
  TooltipTrigger,
} from "~~/registry/bases/newt/ui/tooltip"

/* The content is a slot: the label can bring the keys that do the same thing. */
</script>

<template>
  <Tooltip>
    <TooltipTrigger as-child>
      <Button variant="secondary"> Quick switcher </Button>
    </TooltipTrigger>
    <TooltipContent class="flex items-center gap-1.5">
      Jump to a channel
      <Kbd>Ctrl</Kbd>
      <Kbd>K</Kbd>
    </TooltipContent>
  </Tooltip>
</template>

Sides

The label opens above its trigger. Pass side to TooltipContent to open it on another edge, for example side="bottom" for a trigger at the top edge of the window. It flips by itself when there is no room, and the arrow moves to the side it lands on.

Root class newt-tooltip
import { Button } from "@/registry/bases/newt/ui/button"
import {
  Tooltip,
  TooltipContent,
  TooltipTrigger,
} from "@/registry/bases/newt/ui/tooltip"

const SIDES = [
  { side: "top", label: "Top", text: "Above the trigger" },
  { side: "right", label: "Right", text: "To the right" },
  { side: "bottom", label: "Bottom", text: "Below the trigger" },
  { side: "left", label: "Left", text: "To the left" },
] as const

/*
 * The label opens above its trigger by default. `side` picks another edge.
 * Radix flips it by itself when there is no room on the chosen side, and the
 * arrow follows to the side it lands on.
 */
export default function TooltipSidesDemo() {
  return (
    <div className="flex flex-wrap gap-[var(--newt-space-2)]">
      {SIDES.map(({ side, label, text }) => (
        <Tooltip key={side}>
          <TooltipTrigger asChild>
            <Button variant="secondary">{label}</Button>
          </TooltipTrigger>
          <TooltipContent side={side}>{text}</TooltipContent>
        </Tooltip>
      ))}
    </div>
  )
}
<script setup lang="ts">
import { Button } from "~~/registry/bases/newt/ui/button"
import {
  Tooltip,
  TooltipContent,
  TooltipTrigger,
} from "~~/registry/bases/newt/ui/tooltip"

const sides = [
  { side: "top", label: "Top", text: "Above the trigger" },
  { side: "right", label: "Right", text: "To the right" },
  { side: "bottom", label: "Bottom", text: "Below the trigger" },
  { side: "left", label: "Left", text: "To the left" },
] as const

/*
 * The label opens above its trigger by default. `side` picks another edge.
 * Reka flips it by itself when there is no room on the chosen side, and the
 * arrow follows to the side it lands on.
 */
</script>

<template>
  <div class="flex flex-wrap gap-[var(--newt-space-2)]">
    <Tooltip v-for="item in sides" :key="item.side">
      <TooltipTrigger as-child>
        <Button variant="secondary">{{ item.label }}</Button>
      </TooltipTrigger>
      <TooltipContent :side="item.side">{{ item.text }}</TooltipContent>
    </Tooltip>
  </div>
</template>

Long labels

A label wider than 200px wraps onto more lines and stays centred. Keep it to a sentence or two: a tooltip is a hint.

Root class newt-tooltip
import { Button } from "@/registry/bases/newt/ui/button"
import {
  Tooltip,
  TooltipContent,
  TooltipTrigger,
} from "@/registry/bases/newt/ui/tooltip"

/* A label longer than 200px wraps onto more lines, centred. */
export default function TooltipLongDemo() {
  return (
    <Tooltip>
      <TooltipTrigger asChild>
        <Button variant="secondary">Slow mode</Button>
      </TooltipTrigger>
      <TooltipContent>
        Members can send one message every 30 seconds. Moderators are not
        limited.
      </TooltipContent>
    </Tooltip>
  )
}
<script setup lang="ts">
import { Button } from "~~/registry/bases/newt/ui/button"
import {
  Tooltip,
  TooltipContent,
  TooltipTrigger,
} from "~~/registry/bases/newt/ui/tooltip"

/* A label longer than 200px wraps onto more lines, centred. */
</script>

<template>
  <Tooltip>
    <TooltipTrigger as-child>
      <Button variant="secondary"> Slow mode </Button>
    </TooltipTrigger>
    <TooltipContent>
      Members can send one message every 30 seconds. Moderators are not limited.
    </TooltipContent>
  </Tooltip>
</template>

API reference

Tooltip

PropType
delay?number

Milliseconds the pointer rests on the trigger before it opens. Keyboard focus opens it at once. Without it, the tooltip takes the provider's delay.

Typenumber
Default0
open / defaultOpen / onOpenChange?boolean

Control the open state yourself. Vue uses `v-model:open`.

Typeboolean

TooltipContent

PropType
side?"top" | "right" | "bottom" | "left"

Preferred side. Flips when there is no room.

Type"top" | "right" | "bottom" | "left"
Default"top"
align?"start" | "center" | "end"

Which edge of the trigger the label lines up with.

Type"start" | "center" | "end"
Default"center"
sideOffset?number

Extra gap in pixels between the trigger and the arrow tip. At 0 the bubble sits 8px, the arrow's height, from the trigger.

Typenumber
Default0
container?HTMLElement

Element the label is portalled into. Pass the enclosing native `<dialog>` or a themed wrapper to keep it there.

TypeHTMLElement
Defaultdocument.body

A tooltip needs no setup. To give a group of tooltips one set of delays, wrap the group in TooltipProvider. After one tooltip closes, the next one opens with no wait.

TooltipProvider

PropType
delay?number

Milliseconds the pointer rests on a trigger before its tooltip opens, for every tooltip inside. This is where the default lives; a `Tooltip` without a provider brings one with the same default.

Typenumber
Default0
skipDelayDuration?number

Milliseconds after one tooltip closes during which the next one opens with no delay.

Typenumber
Default300

Every part also accepts the native attributes of the element it renders, and a className that is merged rather than replaced.

Accessibility

The bubble is linked to its trigger with aria-describedby while it is open, so it is read as a description rather than as the name. It opens on hover and, at once, on keyboard focus. Escape dismisses it. Do not put a control inside a tooltip: it cannot be reached by keyboard.

The arrow is decorative and hidden from assistive technology. With reduced motion, the bubble appears and disappears with no fade and no growth.

In the HTML version, wrap the trigger and its .newt-tooltip__bubble in .newt-tooltip, give the bubble role="tooltip" and an id, and point the trigger’s aria-describedby at it. The bubble shows on hover and while anything in the wrapper has keyboard focus (:focus-visible), so a click on the trigger does not keep it open. Load tooltip.js once on the page so Escape hides an open bubble; it stays hidden until the pointer leaves the wrapper or focus moves out of it. When keyboard focus opened the bubble, that Escape stops there, so a dialog behind it, a native <dialog> included, closes on the next press. Without the script the bubble is CSS only and Escape does not hide it. Add .newt-tooltip--bottom, --start or --end to the wrapper for another side; --start and --end follow the reading direction. It does not flip when there is no room. Set --newt-tooltip-delay on the wrapper for a hover delay.

Tokens

Tooltip reads its colours, radii and motion from the --newt-* tokens installed with the library. Override a token and every component that reads it follows, including this one — see the token layer. In the plain HTML and CSS distribution the same component is newt-tooltip.

  • --newt-space-2
  • --newt-dir
  • --newt-space-3
  • --newt-radius-md
  • --newt-bg-floating
  • --newt-border-subtle
  • --newt-shadow-elevation-high
  • --newt-text-primary
  • --newt-font-size-xs
  • --newt-font-weight-medium
  • --newt-duration-fast
  • --newt-ease-out
  • --newt-space-4