Tooltip for images?

Resurfacing this question from about a year ago… is there a way to make the image caption appear as a tooltip when hovering over an image? Alternatively, something similar to the way help works in other widgets.

yes, you can do this with the html_content component and css

# Importing Streamlit
import streamlit as st

# Define HTML and CSS for the tooltip
html_content = """
.tooltip {
  position: relative;
  display: inline-block;
  cursor: pointer;

.tooltip .tooltiptext {
  visibility: hidden;
  width: 120px;
  background-color: black;
  color: white;
  text-align: center;
  border-radius: 6px;
  padding: 5px 0;
  position: absolute;
  z-index: 1;
  top: 100%;
  left: 50%;
  margin-left: -60px;
  opacity: 0;
  transition: opacity 0.3s;

.tooltip:hover .tooltiptext {
  visibility: visible;
  opacity: 1;

<div class="tooltip">
  <img src="" alt="Image" style="width:200px;height:auto;">
  <span class="tooltiptext">Tooltip text</span>

# Display HTML in Streamlit
st.markdown(html_content, unsafe_allow_html=True)

1 Like

Thanks for this suggestion. It’ll work for sure, however I was hoping to find a solution which will work on the st.image widget, rather than st.markdown. Much appreciated.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.