Display a short message, known as a notification "toast".

The toast appears in the app's bottom-right corner and disappears after four seconds.

Warning

st.toast is not compatible with Streamlit's caching and cannot be called within a cached function.

Function signature[source]

st.toast(body, *, icon=None)

Parameters

body (str)

The string to display as Github-flavored Markdown. Syntax information can be found at: https://github.github.com/gfm.

This also supports:

  • Emoji shortcodes, such as :+1: and :sunglasses:. For a list of all supported codes, see https://share.streamlit.io/streamlit/emoji-shortcodes.
  • LaTeX expressions, by wrapping them in "$" or "$$" (the "$$" must be on their own lines). Supported LaTeX functions are listed at https://katex.org/docs/supported.html.
  • Colored text and background colors for text, using the syntax :color[text to be colored] and :color-background[text to be colored], respectively. color must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. For example, you can use :orange[your text here] or :blue-background[your text here].

icon (str, None)

An optional emoji or icon to display next to the alert. If icon is None (default), no icon is displayed. If icon is a string, the following options are valid:

  • A single-character emoji. For example, you can set icon="๐Ÿšจ" or icon="๐Ÿ”ฅ". Emoji short codes are not supported.

  • An icon from the Material Symbols library (outlined style) in the format ":material/icon_name:" where "icon_name" is the name of the icon in snake case.

    For example, icon=":material/thumb_up:" will display the Thumb Up icon. Find additional icons in the Material Symbols font library.

Example

import streamlit as st

st.toast('Your edited image was saved!', icon='๐Ÿ˜')

When multiple toasts are generated, they will stack. Hovering over a toast will stop it from disappearing. When hovering ends, the toast will disappear after four more seconds.

import streamlit as st import time if st.button('Three cheers'): st.toast('Hip!') time.sleep(.5) st.toast('Hip!') time.sleep(.5) st.toast('Hooray!', icon='๐ŸŽ‰')

Toast messages can also be updated. Assign st.toast(my_message) to a variable and use the .toast() method to update it. Note: if a toast has already disappeared or been dismissed, the update will not be seen.

import streamlit as st import time def cook_breakfast(): msg = st.toast('Gathering ingredients...') time.sleep(1) msg.toast('Cooking...') time.sleep(1) msg.toast('Ready!', icon = "๐Ÿฅž") if st.button('Cook breakfast'): cook_breakfast()
forum

Still have questions?

Our forums are full of helpful information and Streamlit experts.