gt-extras
  • Get Started
  • API Reference
  1. HTML Helpers
  2. with_tooltip
  • API Reference
  • Plotting
    • gt_plt_bar
    • gt_plt_dot
    • gt_plt_conf_int
  • Colors
    • gt_highlight_cols
    • gt_hulk_col_numeric
    • gt_color_box
  • Themes
    • gt_theme_538
    • gt_theme_espn
    • gt_theme_guardian
    • gt_theme_nytimes
    • gt_theme_excel
    • gt_theme_dot_matrix
    • gt_theme_dark
    • gt_theme_pff
  • Icons and Images
    • fa_icon_repeat
    • gt_fa_rating
  • HTML Helpers
    • gt_hyperlink
    • with_tooltip

On this page

  • Parameters
  • Returns
  • Examples
  1. HTML Helpers
  2. with_tooltip

with_tooltip

with_tooltip(label, tooltip, text_decoration_style='dotted', color='blue')

Create HTML text with tooltip functionality for use in GT table cells.

The with_tooltip() function creates an HTML <abbr> element with a tooltip that appears when users hover over the text. The text can be styled with customizable underline styles and colors to indicate it’s interactive.

Parameters

label : str

A string that will be displayed as the visible text.

tooltip : str

A string that will appear as the tooltip when hovering over the label.

text_decoration_style : Literal['solid', 'dotted', 'none'] = 'dotted'

A string indicating the style of underline decoration. Options are "solid", "dotted", or “none”.

color : str | Literal['none'] = 'blue'

A string indicating the text color. If “none”, no color styling is applied.

Returns

: str

An HTML string containing the formatted tooltip element.

Examples

import pandas as pd
from great_tables import GT
import gt_extras as gte

df = pd.DataFrame(
    {
        "name": ["Great Tables", "Plotnine", "Quarto"],
        "description": [
            "Absolutely Delightful Table-making in Python",
            "A grammar of graphics for Python",
            "An open-source scientific and technical publishing system",
        ],
    }
)

df["Package"] = [
    gte.with_tooltip(name, description, color = "none")
    for name, description in zip(df["name"], df["description"])
]

GT(df[["Package"]])
Package
Great Tables
Plotnine
Quarto
gt_hyperlink