Skip to main content

What are you looking for?

Try searching for…

Components

Tooltip

Tooltip displays brief information when the user hovers over or focuses on an element. It is used for secondary information, such as explaining the meaning of an icon.

children
Description

The element or string that triggers the tooltip. @note If it is a string, it will be wrapped in a span. @note If it is an element, it needs to be able to receive a ref.

Type
string | (ReactElement<unknown, string | JSXElementConstructor<any>> & RefAttributes<HTMLElement>)
content
Description

Content of the tooltip

Type
string
placement
Description

Placement of the tooltip on the trigger.

Type
Placement
Default
top
autoPlacement
Description

Whether to enable auto placement.

Type
boolean
Default
true
open
Description

Whether the tooltip is open or not. This overrides the internal state of the tooltip. @deprecated This should not be used on Tooltip. Use a Popover instead @TODO Look at this prop

Type
boolean
type
Description

Override if `aria-describedby` or `aria-labelledby` is used. By default, if the trigger element has no inner text, `aria-labelledby` is used.

Type
"describedby" | "labelledby"
NameTypeDefaultDescription
childrenstring | (ReactElement<unknown, string | JSXElementConstructor<any>> & RefAttributes<HTMLElement>)-

The element or string that triggers the tooltip. @note If it is a string, it will be wrapped in a span. @note If it is an element, it needs to be able to receive a ref.

contentstring-

Content of the tooltip

placementPlacementtop

Placement of the tooltip on the trigger.

autoPlacementbooleantrue

Whether to enable auto placement.

openboolean-

Whether the tooltip is open or not. This overrides the internal state of the tooltip. @deprecated This should not be used on Tooltip. Use a Popover instead @TODO Look at this prop

type"describedby" | "labelledby"-

Override if `aria-describedby` or `aria-labelledby` is used. By default, if the trigger element has no inner text, `aria-labelledby` is used.

Usage

Examples

With text

Placement

Use the placement prop to adjust the placement of the Tooltip.

HTML

Use the @digdir/designsystemet-web package to implement Tooltip. You only need to add the data-tooltip attribute to the element that will trigger the tooltip. For accessibility, the element will automatically receive either aria-label or aria-description, depending on whether it contains text content.

Custom element

Use the setTooltipElement function to set a custom tooltip element. The element will auto automatically be added do document.body if it is not already in the document.

CSS variables and data attributes

CSS Variables
NameValue
--dsc-tooltip-backgroundvar(--ds-color-neutral-text-default)
--dsc-tooltip-colorvar(--ds-color-neutral-background-default)
--dsc-tooltip-border-radiusvar(--ds-border-radius-default)
--dsc-tooltip-paddingvar(--ds-size-1) var(--ds-size-2)
--dsc-tooltip-arrow-sizevar(--ds-size-2)
--dsc-tooltip-transition-duration0.2s
--dsc-tooltip-transition-delay150ms
--dsc-tooltip-placementtop
Data Attributes
NameValue
data-tooltip
data-overscrollcontain
data-floating|top, right, bottom, left
data-floatingbottom, top, left, right
Edit this page on github.com (opens in a new tab)