Show API reference for

Display a feedback widget.

A feedback widget is an icon-based button group available in three styles, as described in options. It is commonly used in chat and AI apps to allow users to rate responses.

Function signature[source]

st.feedback(options="thumbs", *, key=None, default=None, disabled=False, on_change="rerun", args=None, kwargs=None, width="content", bind=None, persist_state=None)

Parameters

options ("thumbs", "faces", or "stars")

The feedback options displayed to the user. options can be one of the following:

  • "thumbs" (default): Streamlit displays a thumb-up and thumb-down button group.
  • "faces": Streamlit displays a row of five buttons with facial expressions depicting increasing satisfaction from left to right.
  • "stars": Streamlit displays a row of star icons, allowing the user to select a rating from one to five stars.

key (str, int, or None)

An optional string or integer to use as the unique key for the widget. If this is None (default), a key will be generated for the widget based on the values of the other parameters. No two widgets may have the same key. Assigning a key stabilizes the widget's identity and preserves its state across reruns even when other parameters change.

Note

Changing options resets the widget even when a key is provided.

A key lets you read or update the widget's value via st.session_state[key]. For more details, see Widget behavior.

Additionally, if key is provided, it will be used as a CSS class name prefixed with st-key-.

default (int or None)

Default feedback value. This must be consistent with the feedback type in options:

  • 0 or 1 if options="thumbs".
  • Between 0 and 4, inclusive, if options="faces" or options="stars".

disabled (bool)

An optional boolean that disables the feedback widget if set to True. The default is False.

on_change (callable, "rerun", "ignore", or None)

How the feedback widget should respond to value changes. This controls whether or not Streamlit reruns the app when the user interacts with the feedback widget. on_change can be one of the following:

  • "rerun" (default): Streamlit will rerun the app when the user commits a new value (clicking an option or clearing the selection).
  • "ignore": Streamlit will not rerun the app when the user commits a new value. The feedback widget still updates in the UI. The new value is available on the next rerun triggered by something else, such as another widget interaction. Ignored commits are held in the browser and are lost if the page is refreshed before that rerun, unless bind="query-params" is set (see bind). Inside st.form, this has no effect: the form already defers all commits until submit.
  • A callable: Streamlit will rerun the app and execute the callable as a callback function before the rest of the app.
  • None: This is the same as on_change="rerun". This value exists for backwards compatibility and shouldn't be used.

args (list or tuple)

An optional list or tuple of args to pass to the callback.

kwargs (dict)

An optional dict of kwargs to pass to the callback.

width ("content", "stretch", or int)

The width of the feedback widget. This can be one of the following:

  • "content" (default): The width of the widget matches the width of its content, but doesn't exceed the width of the parent container.
  • "stretch": The width of the widget matches the width of the parent container.
  • An integer specifying the width in pixels: The widget has a fixed width. If the specified width is greater than the width of the parent container, the width of the widget matches the width of the parent container.

bind ("query-params" or None)

Binding mode for syncing the widget's value with a URL query parameter. If this is None (default), the widget's value is not synced to the URL. When this is set to "query-params", changes to the widget update the URL, and the widget can be initialized or updated through a query parameter in the URL. This requires key to be set. The key is used as the query parameter name.

The query parameter holds the index of the selected option, the same integer the widget returns (e.g., ?rating=4 for five stars). When the widget's value equals its default, the query parameter is removed from the URL to keep it clean. A bound query parameter can't be set or deleted through st.query_params; it can only be programmatically changed through st.session_state.

An empty query parameter (e.g., ?rating=) clears the widget. Invalid query parameter values are ignored and removed from the URL.

When on_change="ignore", Streamlit updates the URL on the same commits described above. As with widgets inside a form, the URL can show a value that Python hasn't received yet. Python receives the new value on the next rerun, so a page load or share uses the updated URL value.

persist_state ("page", "session", or None)

How long to preserve the widget's value when it isn't rendered. If this is None (default), the value is lost when the widget stops being rendered or the user switches pages. If this is "page", the value is preserved only while the user stays on the page where the widget is defined (for example, while the widget is conditionally hidden); it is discarded on a page switch and is not restored if the user returns to the page. If this is "session", the value is preserved for the entire session, including across page switches, so it returns when the user navigates back. This requires key to be set. If bind="query-params" is also set, the binding takes precedence: the value is stored in the URL, so it persists across page switches regardless of the persist_state scope.

Returns

(int or None)

An integer indicating the user's selection, where 0 is the lowest feedback. Higher values indicate more positive feedback. If no option was selected, the widget returns None.

  • For options="thumbs", a return value of 0 indicates thumbs-down, and 1 indicates thumbs-up.
  • For options="faces" and options="stars", return values range from 0 (least satisfied) to 4 (most satisfied).

Examples

Display a feedback widget with stars, and show the selected sentiment:

import streamlit as st

sentiment_mapping = ["one", "two", "three", "four", "five"]
selected = st.feedback("stars")
if selected is not None:
    st.markdown(f"You selected {sentiment_mapping[selected]} star(s).")

Display a feedback widget with thumbs, and show the selected sentiment:

import streamlit as st

sentiment_mapping = [":material/thumb_down:", ":material/thumb_up:"]
selected = st.feedback("thumbs")
if selected is not None:
    st.markdown(f"You selected: {sentiment_mapping[selected]}")
star

Tip

Want a new st.feedback feature or found a bug? Browse open issues and react with a 👍 on the initial post of the ones that matter to you. Your votes help us prioritize what to work on next.

forum

Still have questions?

Our forums are full of helpful information and Streamlit experts.