Tooltip
Introduction
Section titled “Introduction”The Tooltip component displays supplemental information in a small popup anchored to a trigger element. It uses the Popover API together with CSS Anchor Positioning, so placement and fallback behavior are handled by the browser.
When to use
Section titled “When to use”Use the Tooltip component when you need to:
- Explain icon-only controls
- Add short contextual guidance near an action
- Clarify labels or terms without cluttering the UI
- Show non-critical, supplementary content
Quick example
Section titled “Quick example”Learn how to implement the Tooltip component in your project, from simple helper text to positioned variants.
Basic usage
Section titled “Basic usage”---import { Tooltip } from 'accessible-astro-components'---
<Tooltip id="tooltip-help" triggerLabel="More information"> Profile <span slot="tooltip">This is the name visible to other users.</span></Tooltip>Positioning
Section titled “Positioning”<Tooltip id="tooltip-right" position="right" triggerLabel="Open help"> Help <span slot="tooltip">This tooltip appears on the right when possible.</span></Tooltip>Icon-only trigger
Section titled “Icon-only trigger”<Tooltip id="tooltip-icon" triggerLabel="Learn more about notifications"> <span aria-hidden="true">Notifications</span> <span slot="tooltip">Choose when and how you receive updates.</span></Tooltip>Configure the Tooltip component with these available props.
| Prop | Type | Default | Description |
|---|---|---|---|
id | string | - | Unique ID used to connect trigger and tooltip |
position | 'top' | 'bottom' | 'left' | 'right' | 'top' | Preferred tooltip position |
offset | string | 'var(--space-2xs)' | Distance between trigger and tooltip |
triggerLabel | string | undefined | Screen reader label for icon-only or unclear trigger text |
showIcon | boolean | true | Show or hide the default help icon |
class | string | undefined | Additional wrapper classes |
Accessibility
Section titled “Accessibility”Accessibility is built into the component through semantic trigger markup and descriptive relationships:
- Semantic
<button>trigger for keyboard interaction aria-describedbylinking trigger and tooltip textrole="tooltip"on the popup content- Preserved focus visibility from native button behavior
- Reduced motion support through
prefers-reduced-motion
Styling
Section titled “Styling”Make the Tooltip component your own while preserving readability and contrast.
The component exposes CSS custom properties for spacing and animation behavior:
--tooltip-offset--transition-duration--transition-easing--translate-offset-x--translate-offset-y
You can provide a custom class via the class prop and override styles using global selectors in your project stylesheet.
Interactive examples
Section titled “Interactive examples”See the Tooltip component in action with common usage patterns.