Tooltip

The <Tooltip> component displays additional information when users hover over text or code elements. Use tooltips to provide context, definitions, or explanations without cluttering your documentation.

Usage

Documentation becomes more interactive when you add tooltips to key terms.

Markdown
1Documentation becomes more interactive when you add <Tooltip tip="A simple tooltip for basic explanations">tooltips</Tooltip> to key terms.

Variants

Rich content

You can include rich content with custom positioning for more detailed explanations

Markdown
1You can include <Tooltip
2 tip={
3 <div>
4 <strong>Rich Content</strong>
5 <br /><br />
6 Supports HTML formatting, <a href="https://buildwithfern.com/" target="_blank">external links</a>, and <code>inline code</code>
7 </div>
8 }
9 side="right"
10>rich content</Tooltip> with custom positioning for more detailed explanations.

Code tooltips

The code tooltip component allows you to provide contextual information for variables and values within your code examples. When users hover over highlighted code, they can see explanations, documentation links, or additional context without leaving the code example.

1const apiKey = "{{API_KEY}}";
Markdown
1<Template
2 data={{ API_KEY: "123456" }}
3 tooltips={{
4 API_KEY: (
5 <p>
6 Your API key is used to authenticate requests to our API. Keep this secure and never expose it in client-side code.
7 </p>
8 )
9 }}
10>
11
12```ts
13const apiKey = "{{API_KEY}}";
14```
15
16</Template>

Multiple code tooltips

1// Import required libraries
2import axios from "axios";
3
4// Configure API client with authentication
5const api = axios.create({
6 baseURL: "{{BASE_URL}}",
7 headers: {
8 Authorization: `Bearer {{API_KEY}}`,
9 "Content-Type": "application/json",
10 },
11});
Markdown
1<Template
2 data={{ API_KEY: "example-key-test-123456789",
3 BASE_URL: "https://api.example.com/v1",
4 }}
5 tooltips={{
6 API_KEY: (<p>
7 Your API key is used to authenticate requests to our API. Keep this secure and never expose it in client-side code.
8 <br /><br />
9 You can find your API keys in the <a href="https://dashboard.example.com/settings/api-keys">Dashboard</a>
10 <br /><br />
11 <strong>Note:</strong> Keys prefixed with <code>example-key-test-</code> are for testing, while keys with <code>example-key-live-</code> are for production.
12 </p>),
13 BASE_URL: (<p>
14 The base URL for all API requests. Different environments (test/production) use different base URLs.
15 <br /><br />
16 See our <a href="https://docs.example.com/environments">Environments documentation</a> for more details.
17 </p>),
18 }}
19>
20
21```ts
22// Import required libraries
23import axios from "axios";
24
25// Configure API client with authentication
26const api = axios.create({
27 baseURL: "{{BASE_URL}}",
28 headers: {
29 Authorization: `Bearer {{API_KEY}}`,
30 "Content-Type": "application/json",
31},
32});
33```
34
35</Template>

Properties

Text tooltip properties

tip
string | ReactNodeRequired

The content to display in the tooltip. Can be a simple string or React component for more complex content.

side
'top' | 'right' | 'bottom' | 'left'Defaults to top

Controls which side of the element the tooltip appears on.

sideOffset
numberDefaults to 4

The distance between the tooltip and the trigger element (px).

Code tooltip properties

data
objectRequired

Key-value pairs where the values are displayed in your code blocks.

tooltips
object

Key-value pairs where the values are displayed in the tooltips. The Key for tooltips must match the Key for data.

Style a code tooltip

To customize code tooltips, target the .fern-mdx-tooltip-content selector. You can override CSS variables or add any custom styles:

1.fern-mdx-tooltip-content {
2 --tooltip-padding-x: 1.5rem; /* Horizontal padding inside tooltip */
3 /* Add custom styles here */
4}

Style a text tooltip

To customize text tooltips, target the .fern-mdx-tooltip-trigger selector. You can override CSS variables for common customizations or add any custom styles:

1.fern-mdx-tooltip-trigger {
2 --tooltip-underline-color: blue; /* Color of the underline in default state */
3 --tooltip-underline-hover-color: green; /* Color of the underline on hover */
4 --tooltip-underline-thickness: 2px; /* Thickness of the underline */
5 --tooltip-underline-offset: 2px; /* Distance between text and underline */
6 --tooltip-transition-duration: 0.10s; /* Hover transition speed */
7 /* Add custom styles here */
8}