# Tooltip URL: https://ark-ui.com/docs/components/tooltip Source: https://raw.githubusercontent.com/chakra-ui/ark/refs/heads/main/website/src/content/pages/components/tooltip.mdx A label that provides information on hover or focus. --- ## Anatomy ```tsx ``` ## Examples **Example: basic** #### React ```tsx import { Tooltip } from '@ark-ui/react/tooltip' import { Portal } from '@ark-ui/react/portal' import styles from 'styles/tooltip.module.css' export const Basic = () => ( Hover Me I am a tooltip! ) ``` #### Solid ```tsx import { Tooltip } from '@ark-ui/solid/tooltip' import { Portal } from 'solid-js/web' import styles from 'styles/tooltip.module.css' export const Basic = () => ( Hover Me I am a tooltip! ) ``` #### Vue ```vue ``` #### Svelte ```svelte Hover Me I am a tooltip! ``` ### Controlled To create a controlled Tooltip component, manage the state of whether the tooltip is open using the `open` prop: **Example: controlled** #### React ```tsx import { Portal } from '@ark-ui/react/portal' import { Tooltip } from '@ark-ui/react/tooltip' import { useState } from 'react' import styles from 'styles/tooltip.module.css' import button from 'styles/button.module.css' export const Controlled = () => { const [open, setOpen] = useState(false) return (
setOpen(e.open)}> Hover Me I am a tooltip!
) } ``` #### Solid ```tsx import { Tooltip } from '@ark-ui/solid/tooltip' import { createSignal } from 'solid-js' import { Portal } from 'solid-js/web' import styles from 'styles/tooltip.module.css' export const Controlled = () => { const [open, setOpen] = createSignal(false) return ( <> setOpen(e.open)}> Hover Me I am a tooltip! ) } ``` #### Vue ```vue ``` #### Svelte ```svelte Hover Me I am a tooltip! ``` ### Root Provider An alternative way to control the tooltip is to use the `RootProvider` component and the `useTooltip` hook. This way you can access the state and methods from outside the component. **Example: root-provider** #### React ```tsx import { Tooltip, useTooltip } from '@ark-ui/react/tooltip' import { Portal } from '@ark-ui/react/portal' import styles from 'styles/tooltip.module.css' export const RootProvider = () => { const tooltip = useTooltip() return ( <> Open: {String(tooltip.open)} Hover Me I am a tooltip! ) } ``` #### Solid ```tsx import { Tooltip, useTooltip } from '@ark-ui/solid/tooltip' import { Portal } from 'solid-js/web' import styles from 'styles/tooltip.module.css' export const RootProvider = () => { const tooltip = useTooltip() return ( <> Hover Me I am a tooltip! ) } ``` #### Vue ```vue ``` #### Svelte ```svelte Hover Me I am a tooltip! ``` ### Arrow To display an arrow pointing to the trigger from the tooltip, use the `Tooltip.Arrow` and `Tooltip.ArrowTip` components: **Example: arrow** #### React ```tsx import { Tooltip } from '@ark-ui/react/tooltip' import { Portal } from '@zag-js/react' import styles from 'styles/tooltip.module.css' export const Arrow = () => ( Hover Me I am a tooltip! ) ``` #### Solid ```tsx import { Tooltip } from '@ark-ui/solid/tooltip' import { Portal } from 'solid-js/web' import styles from 'styles/tooltip.module.css' export const Arrow = () => ( Hover Me I am a tooltip! ) ``` #### Vue ```vue ``` #### Svelte ```svelte Hover Me I am a tooltip! ``` ### Delay To configure the open and close delay for the Tooltip, use the `closeDelay` and `openDelay` props: **Example: delay** #### React ```tsx import { Tooltip } from '@ark-ui/react/tooltip' import { Portal } from '@ark-ui/react/portal' import styles from 'styles/tooltip.module.css' export const Delay = () => ( Hover Me I am a tooltip! ) ``` #### Solid ```tsx import { Tooltip } from '@ark-ui/solid/tooltip' import { Portal } from 'solid-js/web' import styles from 'styles/tooltip.module.css' export const Delay = () => ( Hover Me I am a tooltip! ) ``` #### Vue ```vue ``` #### Svelte ```svelte Hover Me I am a tooltip! ``` ### Positioning To customize the position of the Tooltip relative to the trigger, use the `positioning` prop: **Example: positioning** #### React ```tsx import { Tooltip } from '@ark-ui/react/tooltip' import { Portal } from '@ark-ui/react/portal' import styles from 'styles/tooltip.module.css' export const Positioning = () => ( Hover Me I am a tooltip! ) ``` #### Solid ```tsx import { Tooltip } from '@ark-ui/solid/tooltip' import { Portal } from 'solid-js/web' import styles from 'styles/tooltip.module.css' export const Positioning = () => ( Hover Me I am a tooltip! ) ``` #### Vue ```vue ``` #### Svelte ```svelte Hover Me I am a tooltip! ``` ### Context For more control over the Tooltip's functionality, you can use `Tooltip.Context` to access the Tooltip API: **Example: context** #### React ```tsx import { Portal } from '@ark-ui/react/portal' import { Tooltip } from '@ark-ui/react/tooltip' import styles from 'styles/tooltip.module.css' export const Context = () => ( Hover Me {(tooltip) => ( This tooltip is open: {tooltip.open.toString()} )} ) ``` #### Solid ```tsx import { Tooltip } from '@ark-ui/solid/tooltip' import { Portal } from 'solid-js/web' import styles from 'styles/tooltip.module.css' export const Context = () => ( Hover Me {(context) => ( This tooltip is open: {context().open.toString()} )} ) ``` #### Vue ```vue ``` #### Svelte ```svelte Hover Me {#snippet render(context)} This tooltip is open: {context().open.toString()} {/snippet} ``` ### Within Fixed Containers When rendering a tooltip inside a fixed-position container, set `positioning.strategy` to `"fixed"` to ensure proper positioning. **Example: within-fixed** #### React ```tsx import { Portal } from '@ark-ui/react/portal' import { Tooltip } from '@ark-ui/react/tooltip' import styles from 'styles/tooltip.module.css' export const WithinFixed = () => (
Hover Me I am a tooltip!
) ``` ## API Reference ### Props **Component API Reference** #### React **Root Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `aria-label` | `string` | No | Custom label for the tooltip. | | `closeDelay` | `number` | No | The close delay of the tooltip. | | `closeOnClick` | `boolean` | No | Whether the tooltip should close on click | | `closeOnEscape` | `boolean` | No | Whether to close the tooltip when the Escape key is pressed. | | `closeOnPointerDown` | `boolean` | No | Whether to close the tooltip on pointerdown. | | `closeOnScroll` | `boolean` | No | Whether the tooltip should close on scroll | | `defaultOpen` | `boolean` | No | The initial open state of the tooltip when rendered. Use when you don't need to control the open state of the tooltip. | | `disabled` | `boolean` | No | Whether the tooltip is disabled | | `id` | `string` | No | The unique identifier of the machine. | | `ids` | `Partial<{ trigger: string; content: string; arrow: string; positioner: string }>` | No | The ids of the elements in the tooltip. Useful for composition. | | `immediate` | `boolean` | No | Whether to synchronize the present change immediately or defer it to the next frame | | `interactive` | `boolean` | No | Whether the tooltip's content is interactive. In this mode, the tooltip will remain open when user hovers over the content. | | `lazyMount` | `boolean` | No | Whether to enable lazy mounting | | `onExitComplete` | `VoidFunction` | No | Function called when the animation ends in the closed state | | `onOpenChange` | `(details: OpenChangeDetails) => void` | No | Function called when the tooltip is opened. | | `open` | `boolean` | No | The controlled open state of the tooltip | | `openDelay` | `number` | No | The open delay of the tooltip. | | `positioning` | `PositioningOptions` | No | The user provided options used to position the popover content | | `present` | `boolean` | No | Whether the node is present (controlled by the user) | | `skipAnimationOnMount` | `boolean` | No | Whether to allow the initial presence animation. | | `unmountOnExit` | `boolean` | No | Whether to unmount on exit. | **Arrow Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. | **Arrow CSS Variables:** | Variable | Description | |----------|-------------| | `--arrow-size` | The size of the arrow | | `--arrow-size-half` | Half the size of the arrow | | `--arrow-background` | Use this variable to style the arrow background | | `--arrow-offset` | The offset position of the arrow | **ArrowTip Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. | **Content Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. | **Content Data Attributes:** | Attribute | Value | |-----------|-------| | `[data-scope]` | tooltip | | `[data-part]` | content | | `[data-state]` | "open" | "closed" | | `[data-placement]` | The placement of the content | **Positioner Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. | **Positioner CSS Variables:** | Variable | Description | |----------|-------------| | `--reference-width` | The width of the reference element | | `--reference-height` | The height of the root | | `--available-width` | The available width in viewport | | `--available-height` | The available height in viewport | | `--x` | The x position for transform | | `--y` | The y position for transform | | `--z-index` | The z-index value | | `--transform-origin` | The transform origin for animations | **RootProvider Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `value` | `UseTooltipReturn` | Yes | | | `immediate` | `boolean` | No | Whether to synchronize the present change immediately or defer it to the next frame | | `lazyMount` | `boolean` | No | Whether to enable lazy mounting | | `onExitComplete` | `VoidFunction` | No | Function called when the animation ends in the closed state | | `present` | `boolean` | No | Whether the node is present (controlled by the user) | | `skipAnimationOnMount` | `boolean` | No | Whether to allow the initial presence animation. | | `unmountOnExit` | `boolean` | No | Whether to unmount on exit. | **Trigger Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. | **Trigger Data Attributes:** | Attribute | Value | |-----------|-------| | `[data-scope]` | tooltip | | `[data-part]` | trigger | | `[data-expanded]` | Present when expanded | | `[data-state]` | "open" | "closed" | #### Solid **Root Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `aria-label` | `string` | No | Custom label for the tooltip. | | `closeDelay` | `number` | No | The close delay of the tooltip. | | `closeOnClick` | `boolean` | No | Whether the tooltip should close on click | | `closeOnEscape` | `boolean` | No | Whether to close the tooltip when the Escape key is pressed. | | `closeOnPointerDown` | `boolean` | No | Whether to close the tooltip on pointerdown. | | `closeOnScroll` | `boolean` | No | Whether the tooltip should close on scroll | | `defaultOpen` | `boolean` | No | The initial open state of the tooltip when rendered. Use when you don't need to control the open state of the tooltip. | | `disabled` | `boolean` | No | Whether the tooltip is disabled | | `id` | `string` | No | The unique identifier of the machine. | | `ids` | `Partial<{ trigger: string; content: string; arrow: string; positioner: string }>` | No | The ids of the elements in the tooltip. Useful for composition. | | `immediate` | `boolean` | No | Whether to synchronize the present change immediately or defer it to the next frame | | `interactive` | `boolean` | No | Whether the tooltip's content is interactive. In this mode, the tooltip will remain open when user hovers over the content. | | `lazyMount` | `boolean` | No | Whether to enable lazy mounting | | `onExitComplete` | `VoidFunction` | No | Function called when the animation ends in the closed state | | `onOpenChange` | `(details: OpenChangeDetails) => void` | No | Function called when the tooltip is opened. | | `open` | `boolean` | No | The controlled open state of the tooltip | | `openDelay` | `number` | No | The open delay of the tooltip. | | `positioning` | `PositioningOptions` | No | The user provided options used to position the popover content | | `present` | `boolean` | No | Whether the node is present (controlled by the user) | | `skipAnimationOnMount` | `boolean` | No | Whether to allow the initial presence animation. | | `unmountOnExit` | `boolean` | No | Whether to unmount on exit. | **Arrow Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `asChild` | `(props: ParentProps<'div'>) => Element` | No | Use the provided child element as the default rendered element, combining their props and behavior. | **Arrow CSS Variables:** | Variable | Description | |----------|-------------| | `--arrow-size` | The size of the arrow | | `--arrow-size-half` | Half the size of the arrow | | `--arrow-background` | Use this variable to style the arrow background | | `--arrow-offset` | The offset position of the arrow | **ArrowTip Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `asChild` | `(props: ParentProps<'div'>) => Element` | No | Use the provided child element as the default rendered element, combining their props and behavior. | **Content Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `asChild` | `(props: ParentProps<'div'>) => Element` | No | Use the provided child element as the default rendered element, combining their props and behavior. | **Content Data Attributes:** | Attribute | Value | |-----------|-------| | `[data-scope]` | tooltip | | `[data-part]` | content | | `[data-state]` | "open" | "closed" | | `[data-placement]` | The placement of the content | **Positioner Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `asChild` | `(props: ParentProps<'div'>) => Element` | No | Use the provided child element as the default rendered element, combining their props and behavior. | **Positioner CSS Variables:** | Variable | Description | |----------|-------------| | `--reference-width` | The width of the reference element | | `--reference-height` | The height of the root | | `--available-width` | The available width in viewport | | `--available-height` | The available height in viewport | | `--x` | The x position for transform | | `--y` | The y position for transform | | `--z-index` | The z-index value | | `--transform-origin` | The transform origin for animations | **RootProvider Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `value` | `UseTooltipReturn` | Yes | | | `immediate` | `boolean` | No | Whether to synchronize the present change immediately or defer it to the next frame | | `lazyMount` | `boolean` | No | Whether to enable lazy mounting | | `onExitComplete` | `VoidFunction` | No | Function called when the animation ends in the closed state | | `present` | `boolean` | No | Whether the node is present (controlled by the user) | | `skipAnimationOnMount` | `boolean` | No | Whether to allow the initial presence animation. | | `unmountOnExit` | `boolean` | No | Whether to unmount on exit. | **Trigger Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `asChild` | `(props: ParentProps<'button'>) => Element` | No | Use the provided child element as the default rendered element, combining their props and behavior. | **Trigger Data Attributes:** | Attribute | Value | |-----------|-------| | `[data-scope]` | tooltip | | `[data-part]` | trigger | | `[data-expanded]` | Present when expanded | | `[data-state]` | "open" | "closed" | #### Vue **Root Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `aria-label` | `string` | No | Custom label for the tooltip. | | `closeDelay` | `number` | No | The close delay of the tooltip. | | `closeOnClick` | `boolean` | No | Whether the tooltip should close on click | | `closeOnEscape` | `boolean` | No | Whether to close the tooltip when the Escape key is pressed. | | `closeOnPointerDown` | `boolean` | No | Whether to close the tooltip on pointerdown. | | `closeOnScroll` | `boolean` | No | Whether the tooltip should close on scroll | | `defaultOpen` | `boolean` | No | The initial open state of the tooltip when rendered. Use when you don't need to control the open state of the tooltip. | | `disabled` | `boolean` | No | Whether the tooltip is disabled | | `id` | `string` | No | The unique identifier of the machine. | | `ids` | `Partial<{ trigger: string; content: string; arrow: string; positioner: string }>` | No | The ids of the elements in the tooltip. Useful for composition. | | `interactive` | `boolean` | No | Whether the tooltip's content is interactive. In this mode, the tooltip will remain open when user hovers over the content. | | `lazyMount` | `boolean` | No | Whether to enable lazy mounting | | `open` | `boolean` | No | The controlled open state of the tooltip | | `openDelay` | `number` | No | The open delay of the tooltip. | | `positioning` | `PositioningOptions` | No | The user provided options used to position the popover content | | `unmountOnExit` | `boolean` | No | Whether to unmount on exit. | **Arrow Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. | **Arrow CSS Variables:** | Variable | Description | |----------|-------------| | `--arrow-size` | The size of the arrow | | `--arrow-size-half` | Half the size of the arrow | | `--arrow-background` | Use this variable to style the arrow background | | `--arrow-offset` | The offset position of the arrow | **ArrowTip Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. | **Content Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. | **Content Data Attributes:** | Attribute | Value | |-----------|-------| | `[data-scope]` | tooltip | | `[data-part]` | content | | `[data-state]` | "open" | "closed" | | `[data-placement]` | The placement of the content | **Positioner Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. | **Positioner CSS Variables:** | Variable | Description | |----------|-------------| | `--reference-width` | The width of the reference element | | `--reference-height` | The height of the root | | `--available-width` | The available width in viewport | | `--available-height` | The available height in viewport | | `--x` | The x position for transform | | `--y` | The y position for transform | | `--z-index` | The z-index value | | `--transform-origin` | The transform origin for animations | **RootProvider Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `value` | `TooltipApi` | Yes | | | `lazyMount` | `boolean` | No | Whether to enable lazy mounting | | `unmountOnExit` | `boolean` | No | Whether to unmount on exit. | **Trigger Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. | **Trigger Data Attributes:** | Attribute | Value | |-----------|-------| | `[data-scope]` | tooltip | | `[data-part]` | trigger | | `[data-expanded]` | Present when expanded | | `[data-state]` | "open" | "closed" | #### Svelte **Root Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `id` | `string` | Yes | The unique identifier of the machine. | | `aria-label` | `string` | No | Custom label for the tooltip. | | `closeDelay` | `number` | No | The close delay of the tooltip. | | `closeOnClick` | `boolean` | No | Whether the tooltip should close on click | | `closeOnEscape` | `boolean` | No | Whether to close the tooltip when the Escape key is pressed. | | `closeOnPointerDown` | `boolean` | No | Whether to close the tooltip on pointerdown. | | `closeOnScroll` | `boolean` | No | Whether the tooltip should close on scroll | | `defaultOpen` | `boolean` | No | The initial open state of the tooltip when rendered. Use when you don't need to control the open state of the tooltip. | | `disabled` | `boolean` | No | Whether the tooltip is disabled | | `ids` | `Partial<{ trigger: string; content: string; arrow: string; positioner: string }>` | No | The ids of the elements in the tooltip. Useful for composition. | | `immediate` | `boolean` | No | Whether to synchronize the present change immediately or defer it to the next frame | | `interactive` | `boolean` | No | Whether the tooltip's content is interactive. In this mode, the tooltip will remain open when user hovers over the content. | | `lazyMount` | `boolean` | No | Whether to enable lazy mounting | | `onExitComplete` | `VoidFunction` | No | Function called when the animation ends in the closed state | | `onOpenChange` | `(details: OpenChangeDetails) => void` | No | Function called when the tooltip is opened. | | `open` | `boolean` | No | The controlled open state of the tooltip | | `openDelay` | `number` | No | The open delay of the tooltip. | | `positioning` | `PositioningOptions` | No | The user provided options used to position the popover content | | `present` | `boolean` | No | Whether the node is present (controlled by the user) | | `skipAnimationOnMount` | `boolean` | No | Whether to allow the initial presence animation. | | `unmountOnExit` | `boolean` | No | Whether to unmount on exit. | **Arrow Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `asChild` | `Snippet<[PropsFn<'div'>]>` | No | Use the provided child element as the default rendered element, combining their props and behavior. | | `ref` | `Element` | No | | **Arrow CSS Variables:** | Variable | Description | |----------|-------------| | `--arrow-size` | The size of the arrow | | `--arrow-size-half` | Half the size of the arrow | | `--arrow-background` | Use this variable to style the arrow background | | `--arrow-offset` | The offset position of the arrow | **ArrowTip Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `asChild` | `Snippet<[PropsFn<'div'>]>` | No | Use the provided child element as the default rendered element, combining their props and behavior. | | `ref` | `Element` | No | | **Content Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `asChild` | `Snippet<[PropsFn<'div'>]>` | No | Use the provided child element as the default rendered element, combining their props and behavior. | | `ref` | `Element` | No | | **Content Data Attributes:** | Attribute | Value | |-----------|-------| | `[data-scope]` | tooltip | | `[data-part]` | content | | `[data-state]` | "open" | "closed" | | `[data-placement]` | The placement of the content | **Context Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `render` | `Snippet<[UseTooltipContext]>` | No | | **Positioner Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `asChild` | `Snippet<[PropsFn<'div'>]>` | No | Use the provided child element as the default rendered element, combining their props and behavior. | | `ref` | `Element` | No | | **Positioner CSS Variables:** | Variable | Description | |----------|-------------| | `--reference-width` | The width of the reference element | | `--reference-height` | The height of the root | | `--available-width` | The available width in viewport | | `--available-height` | The available height in viewport | | `--x` | The x position for transform | | `--y` | The y position for transform | | `--z-index` | The z-index value | | `--transform-origin` | The transform origin for animations | **RootProvider Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `value` | `UseTooltipReturn` | Yes | | | `immediate` | `boolean` | No | Whether to synchronize the present change immediately or defer it to the next frame | | `lazyMount` | `boolean` | No | Whether to enable lazy mounting | | `onExitComplete` | `VoidFunction` | No | Function called when the animation ends in the closed state | | `present` | `boolean` | No | Whether the node is present (controlled by the user) | | `skipAnimationOnMount` | `boolean` | No | Whether to allow the initial presence animation. | | `unmountOnExit` | `boolean` | No | Whether to unmount on exit. | **Trigger Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `asChild` | `Snippet<[PropsFn<'button'>]>` | No | Use the provided child element as the default rendered element, combining their props and behavior. | | `ref` | `Element` | No | | **Trigger Data Attributes:** | Attribute | Value | |-----------|-------| | `[data-scope]` | tooltip | | `[data-part]` | trigger | | `[data-expanded]` | Present when expanded | | `[data-state]` | "open" | "closed" | ### Context **API:** | Property | Type | Description | |----------|------|-------------| | `open` | `boolean` | Whether the tooltip is open. | | `setOpen` | `(open: boolean) => void` | Function to open the tooltip. | | `reposition` | `(options?: Partial) => void` | Function to reposition the popover | ## Accessibility Complies with the [Tooltip WAI-ARIA design pattern](https://www.w3.org/WAI/ARIA/apg/patterns/tooltip/). ### Keyboard Support