
# Tooltip



> Tooltip component provides context or additional information for the element it is attached to.

## Examples

### Default

```tsx
import { Button, Tooltip } from "@kesko/components";
import { IconQuestion } from "@kesko/iconography/react";

export default () => (
  <>
    <Button appearance="text" square className="k-cursor-help" aria-describedby="delivery-help">
      <IconQuestion label="About delivery times" />
    </Button>
    <Tooltip id="delivery-help" defaultOpen>
      Orders placed before noon are delivered the same day.
    </Tooltip>
  </>
);

```

```html
<button class="k-button k-cursor-help" appearance="text" square type="button" aria-describedby="delivery-help">
  <svg viewBox="0 0 24 24" role="img" aria-label="About delivery times" xmlns="http://www.w3.org/2000/svg"><path d="M13.088 11.78c-.34.325-.523.55-.538 1.145-.015.142-.07.255-.24.282l-.762.128c-.17.027-.268-.07-.283-.24l-.058-.75c-.112-1.568 1.808-1.963 1.823-3.065 0-.537-.437-.848-1.157-.848-.65 0-1.258.255-1.865.635-.17.1-.31.043-.395-.127l-.423-.89c-.085-.17-.07-.298.113-.425.635-.425 1.637-.79 2.74-.79 1.625 0 2.852.875 2.852 2.275s-1.172 2.063-1.807 2.67zm-1.2 2.98c-.735 0-1.23.522-1.23 1.188s.495 1.2 1.23 1.2 1.23-.523 1.23-1.2-.495-1.188-1.23-1.188zm8.137-8.717a.396.396 0 0 0-.603-.048l-.505.505a.399.399 0 0 0-.035.52 8.45 8.45 0 0 1 1.62 4.982c0 4.688-3.812 8.5-8.5 8.5S3.5 16.687 3.5 12 7.313 3.5 12 3.5c1.86 0 3.58.602 4.983 1.62.16.117.38.105.52-.035l.505-.505a.4.4 0 0 0-.048-.603A9.945 9.945 0 0 0 12 2.002c-5.515 0-10 4.485-10 10s4.485 10 10 10 10-4.485 10-10c0-2.23-.735-4.292-1.975-5.957z" fill="currentColor" /></svg>
</button>
<k-tooltip id="delivery-help" role="tooltip" popover="manual">Orders placed before noon are delivered the same day.</k-tooltip>

<script type="module">
  import "@kesko/components/vanilla";
</script>
```

### Custom style

```tsx
import { Button, Tooltip } from "@kesko/components";
import { IconQuestion } from "@kesko/iconography/react";

export default () => (
  <>
    <Button appearance="text" square className="k-cursor-help" aria-describedby="loyalty-help">
      <IconQuestion label="About Plussa points" />
    </Button>
    <Tooltip
      id="loyalty-help"
      style={{
        "--k-tooltip-bg": "var(--k-color-bg-inverted)",
        "--k-tooltip-text": "var(--k-color-text-inverted)",
        "--k-tooltip-radius": "var(--k-radius-sm)",
      }}
    >
      Plussa points are added to your account within two days.
    </Tooltip>
  </>
);

```

```html
<button class="k-button k-cursor-help" appearance="text" square type="button" aria-describedby="loyalty-help">
  <svg viewBox="0 0 24 24" role="img" aria-label="About Plussa points" xmlns="http://www.w3.org/2000/svg"><path d="M13.088 11.78c-.34.325-.523.55-.538 1.145-.015.142-.07.255-.24.282l-.762.128c-.17.027-.268-.07-.283-.24l-.058-.75c-.112-1.568 1.808-1.963 1.823-3.065 0-.537-.437-.848-1.157-.848-.65 0-1.258.255-1.865.635-.17.1-.31.043-.395-.127l-.423-.89c-.085-.17-.07-.298.113-.425.635-.425 1.637-.79 2.74-.79 1.625 0 2.852.875 2.852 2.275s-1.172 2.063-1.807 2.67zm-1.2 2.98c-.735 0-1.23.522-1.23 1.188s.495 1.2 1.23 1.2 1.23-.523 1.23-1.2-.495-1.188-1.23-1.188zm8.137-8.717a.396.396 0 0 0-.603-.048l-.505.505a.399.399 0 0 0-.035.52 8.45 8.45 0 0 1 1.62 4.982c0 4.688-3.812 8.5-8.5 8.5S3.5 16.687 3.5 12 7.313 3.5 12 3.5c1.86 0 3.58.602 4.983 1.62.16.117.38.105.52-.035l.505-.505a.4.4 0 0 0-.048-.603A9.945 9.945 0 0 0 12 2.002c-5.515 0-10 4.485-10 10s4.485 10 10 10 10-4.485 10-10c0-2.23-.735-4.292-1.975-5.957z" fill="currentColor" /></svg>
</button>
<k-tooltip id="loyalty-help" role="tooltip" popover="manual" style="--k-tooltip-bg: var(--k-color-bg-inverted); --k-tooltip-text: var(--k-color-text-inverted); --k-tooltip-radius: var(--k-radius-sm)">Plussa points are added to your account within two days.</k-tooltip>

<script type="module">
  import "@kesko/components/vanilla";
</script>
```

### Open

```tsx
import { Button, Tooltip } from "@kesko/components";
import { IconQuestion } from "@kesko/iconography/react";

export default () => (
  <>
    <Button appearance="text" square className="k-cursor-help" aria-describedby="pickup-help">
      <IconQuestion label="About pickup" />
    </Button>
    <Tooltip id="pickup-help" position="bottom" open>
      Pickup orders are ready two hours after checkout.
    </Tooltip>
  </>
);

```

```html
<button class="k-button k-cursor-help" appearance="text" square type="button" aria-describedby="pickup-help">
  <svg viewBox="0 0 24 24" role="img" aria-label="About pickup" xmlns="http://www.w3.org/2000/svg"><path d="M13.088 11.78c-.34.325-.523.55-.538 1.145-.015.142-.07.255-.24.282l-.762.128c-.17.027-.268-.07-.283-.24l-.058-.75c-.112-1.568 1.808-1.963 1.823-3.065 0-.537-.437-.848-1.157-.848-.65 0-1.258.255-1.865.635-.17.1-.31.043-.395-.127l-.423-.89c-.085-.17-.07-.298.113-.425.635-.425 1.637-.79 2.74-.79 1.625 0 2.852.875 2.852 2.275s-1.172 2.063-1.807 2.67zm-1.2 2.98c-.735 0-1.23.522-1.23 1.188s.495 1.2 1.23 1.2 1.23-.523 1.23-1.2-.495-1.188-1.23-1.188zm8.137-8.717a.396.396 0 0 0-.603-.048l-.505.505a.399.399 0 0 0-.035.52 8.45 8.45 0 0 1 1.62 4.982c0 4.688-3.812 8.5-8.5 8.5S3.5 16.687 3.5 12 7.313 3.5 12 3.5c1.86 0 3.58.602 4.983 1.62.16.117.38.105.52-.035l.505-.505a.4.4 0 0 0-.048-.603A9.945 9.945 0 0 0 12 2.002c-5.515 0-10 4.485-10 10s4.485 10 10 10 10-4.485 10-10c0-2.23-.735-4.292-1.975-5.957z" fill="currentColor" /></svg>
</button>
<k-tooltip id="pickup-help" position="bottom" open role="tooltip" popover="manual">Pickup orders are ready two hours after checkout.</k-tooltip>

<script type="module">
  import "@kesko/components/vanilla";
</script>
```

### Positions

```tsx
import { Button, Grid, Tooltip } from "@kesko/components";

const positions = [
  "top-start",
  "top",
  "top-end",
  "bottom-start",
  "bottom",
  "bottom-end",
  "start-top",
  "start",
  "start-bottom",
  "end-top",
  "end",
  "end-bottom",
] as const;

export default () => (
  <Grid columns={3} gap="xs">
    {positions.map(position => {
      const id = `position-${position}`;
      return (
        <div key={id}>
          <Button size="sm" appearance="outline" expand className="k-cursor-help" aria-describedby={id}>
            {position}
          </Button>
          <Tooltip id={id} position={position}>
            Opens at {position}. Longer text grows the bubble away from the arrow.
          </Tooltip>
        </div>
      );
    })}
  </Grid>
);

```

```html
<k-grid columns="3" gap="xs">
  <div>
    <button class="k-button k-button-sm k-cursor-help" appearance="outline" expand type="button" aria-describedby="position-top-start">top-start</button>
    <k-tooltip id="position-top-start" position="top-start" role="tooltip" popover="manual">Opens at top-start. Longer text grows the bubble away from the arrow.</k-tooltip>
  </div>
  <div>
    <button class="k-button k-button-sm k-cursor-help" appearance="outline" expand type="button" aria-describedby="position-top">top</button>
    <k-tooltip id="position-top" role="tooltip" popover="manual">Opens at top. Longer text grows the bubble away from the arrow.</k-tooltip>
  </div>
  <div>
    <button class="k-button k-button-sm k-cursor-help" appearance="outline" expand type="button" aria-describedby="position-top-end">top-end</button>
    <k-tooltip id="position-top-end" position="top-end" role="tooltip" popover="manual">Opens at top-end. Longer text grows the bubble away from the arrow.</k-tooltip>
  </div>
  <div>
    <button class="k-button k-button-sm k-cursor-help" appearance="outline" expand type="button" aria-describedby="position-bottom-start">bottom-start</button>
    <k-tooltip id="position-bottom-start" position="bottom-start" role="tooltip" popover="manual">Opens at bottom-start. Longer text grows the bubble away from the arrow.</k-tooltip>
  </div>
  <div>
    <button class="k-button k-button-sm k-cursor-help" appearance="outline" expand type="button" aria-describedby="position-bottom">bottom</button>
    <k-tooltip id="position-bottom" position="bottom" role="tooltip" popover="manual">Opens at bottom. Longer text grows the bubble away from the arrow.</k-tooltip>
  </div>
  <div>
    <button class="k-button k-button-sm k-cursor-help" appearance="outline" expand type="button" aria-describedby="position-bottom-end">bottom-end</button>
    <k-tooltip id="position-bottom-end" position="bottom-end" role="tooltip" popover="manual">Opens at bottom-end. Longer text grows the bubble away from the arrow.</k-tooltip>
  </div>
  <div>
    <button class="k-button k-button-sm k-cursor-help" appearance="outline" expand type="button" aria-describedby="position-start-top">start-top</button>
    <k-tooltip id="position-start-top" position="start-top" role="tooltip" popover="manual">Opens at start-top. Longer text grows the bubble away from the arrow.</k-tooltip>
  </div>
  <div>
    <button class="k-button k-button-sm k-cursor-help" appearance="outline" expand type="button" aria-describedby="position-start">start</button>
    <k-tooltip id="position-start" position="start" role="tooltip" popover="manual">Opens at start. Longer text grows the bubble away from the arrow.</k-tooltip>
  </div>
  <div>
    <button class="k-button k-button-sm k-cursor-help" appearance="outline" expand type="button" aria-describedby="position-start-bottom">start-bottom</button>
    <k-tooltip id="position-start-bottom" position="start-bottom" role="tooltip" popover="manual">Opens at start-bottom. Longer text grows the bubble away from the arrow.</k-tooltip>
  </div>
  <div>
    <button class="k-button k-button-sm k-cursor-help" appearance="outline" expand type="button" aria-describedby="position-end-top">end-top</button>
    <k-tooltip id="position-end-top" position="end-top" role="tooltip" popover="manual">Opens at end-top. Longer text grows the bubble away from the arrow.</k-tooltip>
  </div>
  <div>
    <button class="k-button k-button-sm k-cursor-help" appearance="outline" expand type="button" aria-describedby="position-end">end</button>
    <k-tooltip id="position-end" position="end" role="tooltip" popover="manual">Opens at end. Longer text grows the bubble away from the arrow.</k-tooltip>
  </div>
  <div>
    <button class="k-button k-button-sm k-cursor-help" appearance="outline" expand type="button" aria-describedby="position-end-bottom">end-bottom</button>
    <k-tooltip id="position-end-bottom" position="end-bottom" role="tooltip" popover="manual">Opens at end-bottom. Longer text grows the bubble away from the arrow.</k-tooltip>
  </div>
</k-grid>

<script type="module">
  import "@kesko/components/vanilla";
</script>
```

### Shared tooltip

```tsx
import { Button, Stack, Tooltip } from "@kesko/components";

const rows = ["Weekly groceries", "Garden tools", "Winter tyres"];

export default () => (
  <Stack gap="sm">
    {rows.map(row => (
      <Stack key={row} direction="row" justify="between" alignment="center" gap="lg">
        <span>{row}</span>
        <Button size="sm" appearance="outline" aria-describedby="edit-row">
          Edit
        </Button>
      </Stack>
    ))}
    <Tooltip id="edit-row">Edit this order.</Tooltip>
  </Stack>
);

```

```html
<k-stack gap="sm">
  <k-stack direction="row" justify="between" alignment="center" gap="lg">
    <span>Weekly groceries</span>
    <button class="k-button k-button-sm" appearance="outline" type="button" aria-describedby="edit-row">Edit</button>
  </k-stack>
  <k-stack direction="row" justify="between" alignment="center" gap="lg">
    <span>Garden tools</span>
    <button class="k-button k-button-sm" appearance="outline" type="button" aria-describedby="edit-row">Edit</button>
  </k-stack>
  <k-stack direction="row" justify="between" alignment="center" gap="lg">
    <span>Winter tyres</span>
    <button class="k-button k-button-sm" appearance="outline" type="button" aria-describedby="edit-row">Edit</button>
  </k-stack>
  <k-tooltip id="edit-row" role="tooltip" popover="manual">Edit this order.</k-tooltip>
</k-stack>

<script type="module">
  import "@kesko/components/vanilla";
</script>
```

### Without arrow

```tsx
import { Button, Tooltip } from "@kesko/components";
import { IconQuestion } from "@kesko/iconography/react";

export default () => (
  <>
    <Button appearance="text" square className="k-cursor-help" aria-describedby="returns-help">
      <IconQuestion label="About returns" />
    </Button>
    <Tooltip id="returns-help" arrow={false}>
      Returns are free for 30 days.
    </Tooltip>
  </>
);

```

```html
<button class="k-button k-cursor-help" appearance="text" square type="button" aria-describedby="returns-help">
  <svg viewBox="0 0 24 24" role="img" aria-label="About returns" xmlns="http://www.w3.org/2000/svg"><path d="M13.088 11.78c-.34.325-.523.55-.538 1.145-.015.142-.07.255-.24.282l-.762.128c-.17.027-.268-.07-.283-.24l-.058-.75c-.112-1.568 1.808-1.963 1.823-3.065 0-.537-.437-.848-1.157-.848-.65 0-1.258.255-1.865.635-.17.1-.31.043-.395-.127l-.423-.89c-.085-.17-.07-.298.113-.425.635-.425 1.637-.79 2.74-.79 1.625 0 2.852.875 2.852 2.275s-1.172 2.063-1.807 2.67zm-1.2 2.98c-.735 0-1.23.522-1.23 1.188s.495 1.2 1.23 1.2 1.23-.523 1.23-1.2-.495-1.188-1.23-1.188zm8.137-8.717a.396.396 0 0 0-.603-.048l-.505.505a.399.399 0 0 0-.035.52 8.45 8.45 0 0 1 1.62 4.982c0 4.688-3.812 8.5-8.5 8.5S3.5 16.687 3.5 12 7.313 3.5 12 3.5c1.86 0 3.58.602 4.983 1.62.16.117.38.105.52-.035l.505-.505a.4.4 0 0 0-.048-.603A9.945 9.945 0 0 0 12 2.002c-5.515 0-10 4.485-10 10s4.485 10 10 10 10-4.485 10-10c0-2.23-.735-4.292-1.975-5.957z" fill="currentColor" /></svg>
</button>
<k-tooltip id="returns-help" arrow="false" role="tooltip" popover="manual">Returns are free for 30 days.</k-tooltip>

<script type="module">
  import "@kesko/components/vanilla";
</script>
```


## Props

- `id` — `string` The id that triggers point at. Any element whose `aria-describedby` lists this id shows the tooltip on hover and keyboard focus, so the same text can describe several triggers.
- `position` — `"top" | "top-start" | "top-end" | "bottom" | "bottom-start" | "bottom-end" | "start" | "start-top" | "start-bottom" | "end" | "end-top" | "end-bottom"` (default: `"top"`) The side of the trigger the tooltip opens on, and optionally which edge of the tooltip the arrow sits at. `start` and `end` follow the writing direction. The tooltip flips to the opposite side when there is no room, and opens above or below when neither `start` nor `end` has room.
- `arrow` — `boolean` (default: `true`) Shows the arrow that points at the trigger.
- `delay` — `number` (default: `300`) Milliseconds the pointer rests on the trigger before the tooltip opens. Keyboard focus and clicking or tapping the trigger open it right away.
- `defaultOpen` — `boolean` (default: `false`) Shows the tooltip as soon as it mounts, as a one-time hint. It closes like any other tooltip and then follows hover and focus.
- `open` — `boolean` Keeps the tooltip open regardless of hover and focus, for example in a showcase. Leave it out for a tooltip that people trigger themselves.

## CSS custom properties

- `--k-tooltip-bg` (default: `var(--k-color-bg-base)`) Overrides the background color.
- `--k-tooltip-text` (default: `var(--k-color-text-base)`) Overrides the text color.
- `--k-tooltip-radius` (default: `var(--k-radius-lg)`) Overrides the border radius.
- `--k-tooltip-shadow` (default: `var(--k-shadow-float)`) Overrides the shadow of the bubble. The arrow keeps a small shadow of its own.
- `--k-tooltip-max-size` (default: `15rem`) Overrides the maximum width. The tooltip hugs its text up to this.

## Accessibility

Tooltip is built on a `<k-tooltip>` element with `role="tooltip"`. The trigger points at it with `aria-describedby`, so a screen reader reads the tooltip text right after the trigger’s name.

- **The trigger needs a name of its own.** A tooltip describes, it does not label. An icon-only button gets its name from the icon’s `label` or from `aria-label`, and the tooltip adds detail on top. Never use the `title` attribute instead.
- **Only focusable elements can trigger it.** Keyboard users reach the tooltip through focus, so put `aria-describedby` on a button, link or form control, not on a plain icon or span.
- **Plain text only.** A tooltip disappears when the pointer leaves, so people cannot interact with anything inside it. Links, buttons and formatted content belong in a popover.
- **Never put essential information in a tooltip.** Touch users cannot hover, and the text is easy to miss. Say what matters in the interface and use the tooltip for a hint.
- **Dismissing is handled for you.** The tooltip stays open while hovered, closes on `Esc` or a click elsewhere, and opens on tap.
- **One at a time.** Opening a tooltip closes any other tooltip on the page, so the screen never fills up with hints.
- **Check contrast if you override colors.** `--k-tooltip-text` needs 4.5:1 against `--k-tooltip-bg`. Verify with the [WebAIM contrast checker](https://webaim.org/resources/contrastchecker/).

See the [accessibility guidelines](/accessibility/) and the [A11Y checklist](/a11y-checklist/) for more details.

## Integration

Install `@kesko/components` together with `@kesko/css`, which provides the design tokens and base styles it depends on, and `@kesko/themes` for your brand:

```sh
npm install @kesko/components @kesko/css @kesko/themes
```

Then load the base stylesheet and one brand theme once, in your app's entry point or root layout. Leave out `@kesko/css/components`: it mirrors the component styles for plain HTML, and `@kesko/components` already ships them.

```tsx
import "@kesko/css";
import "@kesko/themes/dist/k-rauta.css";
```

Finally, import the component into your project:

```tsx
import { Tooltip } from "@kesko/components";
```

Projects without React get the same markup and styling from `@kesko/css` by importing the base stylesheet, the `components` add-on and a brand theme, in that order:

```css
@import "@kesko/css";
@import "@kesko/css/components";
@import "@kesko/themes/dist/k-rauta.css";
```

The HTML examples above show the exact markup to copy.

## Resources

- [Usage guidelines](/components/usage/) — Learn how to use the component library with React, Next.js, or basic HTML.
- [Localization](/localization/) — How to translate the components for multiple languages.
- [CSS Framework](/css/) — Utilities and tokens for everything the components don’t cover.
- [Themes](/themes/) — How to customize the component library theme.
- [Accessibility checklist](/a11y-checklist/) — Interactive, browser-based Kesko accessibility checklist.

