---
title: "Tooltip · UI SDK — StyleX Blocks"
description: "Short contextual labels with a default panel style and an inverted variant."
url: "https://stylexblocks.com/components/ui-sdk/tooltip/"
agent:
  instructions: "Use this search API to find relevant components and blocks across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://stylexblocks.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Tooltip

Short contextual labels with a default panel style and an inverted variant.

- Behavior engine: UI SDK
- Also available for: [Ark UI](https://stylexblocks.com/components/ark-ui/tooltip.md), [Base UI](https://stylexblocks.com/components/base-ui/tooltip.md)
- Category: Feedback
- Variants: inverted
- Used in blocks: [Checkout Form](https://stylexblocks.com/block/ui-sdk/checkout-form.md), [Checkout Wizard](https://stylexblocks.com/block/ui-sdk/checkout-wizard.md), [Comparison Table](https://stylexblocks.com/block/ui-sdk/comparison-table.md), [Kanban Board](https://stylexblocks.com/block/ui-sdk/kanban-board.md), [Theme Showcase](https://stylexblocks.com/block/ui-sdk/theme-showcase.md)
- HTML page: https://stylexblocks.com/components/ui-sdk/tooltip/

## Install

Configure the project once (sets the behavior engine and import aliases):

```sh
npx stylexblocks init --style ui-sdk
```

Then add the item as source you own:

```sh
npx stylexblocks add tooltip
```

Equivalent: `npx shadcn add @stylexblocks/tooltip`. Registry item JSON: https://stylexblocks.com/r/ui-sdk/tooltip.json

## Usage

```tsx
import { Tooltip } from "#components/ui/ui-sdk/tooltip.tsx";
import { Button } from "#components/ui/ui-sdk/button.tsx";

export function Example() {
  return (
    // variant="inverted" flips the surface; Content opens in the browser's
    // top layer (no Portal or Positioner), and tooltips group their delays
    // without a Provider.
    <Tooltip.Root variant="inverted" delay={200} closeDelay={100}>
      <Tooltip.Trigger render={<Button variant="surface" />}>Copy</Tooltip.Trigger>
      <Tooltip.Content sideOffset={8}>
        <Tooltip.Arrow />
        Copy to clipboard
      </Tooltip.Content>
    </Tooltip.Root>
  );
}
```

## Source

`components/ui/ui-sdk/tooltip.tsx`

```tsx
import * as stylex from "@stylexjs/stylex";
import {
  Tooltip as UiSdkTooltip,
  TooltipArrow,
  TooltipContent,
  TooltipTrigger,
} from "@ui-sdk/react/tooltip";
import { createSlotRecipeContext } from "#lib/ui-sdk/create-slot-recipe-context.tsx";
import { defineSlotRecipe, fromMap, resolveSlotStyles } from "#lib/recipe-props.ts";
import { durations } from '@stylexblocks/ui/tokens/durations.stylex.ts'
import { fontSizes } from '@stylexblocks/ui/tokens/font-sizes.stylex.ts'
import { fontWeights } from '@stylexblocks/ui/tokens/font-weights.stylex.ts'
import { lineHeights } from '@stylexblocks/ui/tokens/line-heights.stylex.ts'
import { semanticColors } from '@stylexblocks/ui/semantic-tokens/colors.stylex.ts'
import { semanticRadii } from '@stylexblocks/ui/semantic-tokens/radii.stylex.ts'
import { semanticShadows } from '@stylexblocks/ui/semantic-tokens/shadows.stylex.ts'
import { sizes } from '@stylexblocks/ui/tokens/sizes.stylex.ts'
import { spacing } from '@stylexblocks/ui/tokens/spacing.stylex.ts'
import { zIndices } from '@stylexblocks/ui/tokens/z-indices.stylex.ts'

const tooltipContent = stylex.create({
  base: {
    '--tooltip-bg': semanticColors.bg,
    display: 'flex',
    alignItems: 'center',
    backgroundColor: 'var(--tooltip-bg)',
    color: semanticColors.fg,
    paddingInline: spacing._2_5,
    paddingBlock: spacing._1,
    borderRadius: semanticRadii.panel,
    fontWeight: fontWeights.medium,
    fontSize: fontSizes.xs,
    lineHeight: lineHeights.xs,
    boxShadow: semanticShadows.overlay,
    maxWidth: sizes.xs,
    zIndex: zIndices.tooltip,
    transformOrigin: 'var(--transform-origin)',
    animationName: {
      default: null,
      ':is([data-open], [data-state="open"])': 'scale-in, fade-in',
      ':is([data-closed], [data-state="closed"])': 'scale-out, fade-out',
    },
    animationDuration: {
      default: null,
      ':is([data-open], [data-state="open"])': durations.fast,
      ':is([data-closed], [data-state="closed"])': durations.fast,
    },
  },
})

const tooltipContentVariants = stylex.create({
  inverted: {
    '--tooltip-bg': semanticColors.bgInverted,
    color: semanticColors.fgInverted,
  },
})

const tooltipArrow = stylex.create({
  base: {
    '--arrow-size': sizes._2,
    '--arrow-background': 'var(--tooltip-bg)',
    zIndex: -1,
  },
})

const tooltipArrowTip = stylex.create({
  base: {
    borderTopWidth: '1px',
    borderInlineStartWidth: '1px',
    borderColor: 'var(--tooltip-bg)',
  },
})

export type TooltipVariant = keyof typeof tooltipContentVariants

// The generated variant map is sparse (`inverted` only). An empty `solid`
// entry is the implicit default panel look so `defaultVariants` type-checks.
const tooltipPlain = stylex.create({ solid: {} });

const tooltipRecipe = defineSlotRecipe({
  slots: {
    content: {
      styles: tooltipContent,
      variants: {
        solid: tooltipPlain.solid,
        inverted: tooltipContentVariants.inverted,
      },
    },
    arrow: { styles: tooltipArrow },
    arrowTip: { styles: tooltipArrowTip },
  },
  defaultVariants: { variant: "solid" },
});

// UI SDK's tooltip content is a native popover that stays in the page,
// hidden, from the start (so it can name its trigger). It only takes the
// recipe's `display: flex` while open, and clears the browser's popover
// margin, border and overflow.
const chrome = stylex.create({
  content: {
    display: {
      default: null,
      ":popover-open": "flex",
    },
    margin: 0,
    borderWidth: 0,
    overflow: "visible",
  },
  // UI SDK places the arrow along the edge (`left`/`top`); the cross axis,
  // the diamond, and its color are ours.
  arrow: {
    width: "var(--arrow-size)",
    height: "var(--arrow-size)",
    backgroundColor: "var(--arrow-background)",
    transform: "rotate(45deg)",
    top: {
      default: null,
      ':is([data-side="bottom"])': "calc(var(--arrow-size) / -2)",
    },
    bottom: {
      default: null,
      ':is([data-side="top"])': "calc(var(--arrow-size) / -2)",
    },
    left: {
      default: null,
      ':is([data-side="right"])': "calc(var(--arrow-size) / -2)",
    },
    right: {
      default: null,
      ':is([data-side="left"])': "calc(var(--arrow-size) / -2)",
    },
  },
});

const { withRootProvider, withContext } = createSlotRecipeContext(tooltipRecipe);

/**
 * Tooltip — UI SDK's tooltip wearing the tooltip slot recipe. The content is
 * a native popover in the browser's top layer, so there is no Portal or
 * Positioner: placement props (`side`, `align`, `sideOffset`) go on
 * `Content`. Hover/focus intent, delays (`delay`, `closeDelay` on Root), and
 * grouping across tooltips come from the engine — no Provider needed.
 * `<Tooltip.Root variant>` resolves the recipe once; parts inherit it through
 * context and compose via `render`.
 */
export const Tooltip = {
  Root: withRootProvider(UiSdkTooltip, "TooltipRoot"),
  Trigger: TooltipTrigger,
  Content: withContext(
    TooltipContent,
    (v) => [tooltipContent.base, fromMap(tooltipContentVariants, v.variant), chrome.content],
    "TooltipContent",
  ),
  Arrow: withContext(
    TooltipArrow,
    (v) => [...resolveSlotStyles(tooltipRecipe.slots.arrow, v), chrome.arrow],
    "TooltipArrow",
  ),
};
```
