# st.expander

Source: https://docs.streamlit.io/develop/api-reference/layout/st.expander

* Function signature:

   ```python
   st.expander(label, expanded=False, *, key=None, icon=None, type="default", width="stretch", on_change="ignore", args=None, kwargs=None, bind=None)
   ```

* Parameters:

   | name | type | default | description |
   |---|---|---|---|
   | label | str |  | A string to use as the header for the expander. The label can optionally contain GitHub-flavored Markdown of the following types: Bold, Italics, Strikethroughs, Inline Code, Links, and Images. Images display like icons, with a max height equal to the font height. Unsupported Markdown elements are unwrapped so only their children (text contents) render. Common block-level Markdown (headings, lists, blockquotes) is automatically escaped and displays as literal text in labels. See the body parameter of st.markdown for additional, supported Markdown directives. |
   | expanded | bool |  | If True, initializes the expander in "expanded" state. Defaults to False (collapsed). |
   | 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. When on_change is set to "rerun" or a callable, or when bind="query-params" is set, setting a key lets you read or update the expanded state 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-. |
   | icon | str, None |  | An optional emoji or icon to display next to the expander label. If icon is None (default), no icon is displayed, except with type="step", which falls back to a faded circle placeholder. 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 (rounded 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.  "spinner": Displays a spinner as an icon. |
   | type | "default", "compact", or "step" |  | The visual style of the expander. This can be one of the following:  "default" (default): The expander is displayed with a border and background. "compact": The expander is rendered as a minimal inline toggle, ideal for displaying AI reasoning, thoughts, or collapsible metadata without visual clutter. "step": The expander is rendered as a timeline step with an icon column and a vertical connector line. Consecutive step containers form a connected timeline, which is useful for chain-of-thought output, multi-stage pipelines, and activity feeds. A step without content ends the timeline. Any other element between two steps starts a new timeline segment, even an invisible one like st.empty(). |
   | width | "stretch" or int |  | The width of the expander container. This can be one of the following:  "stretch" (default): The width of the container matches the width of the parent container. An integer specifying the width in pixels: The container has a fixed width. If the specified width is greater than the width of the parent container, the width of the container matches the width of the parent container. |
   | on_change | "ignore", "rerun", or callable |  | How the expander should respond when the user expands or collapses it. This controls whether the expander tracks state and triggers reruns. on_change can be one of the following:  "ignore" (default): Unless bind="query-params" is set, the expander doesn't track state. All expander content runs regardless of whether the expander is open or closed. The .open attribute of the expander container returns None when state tracking is disabled. "rerun": The expander tracks state. Streamlit reruns the app when the user expands or collapses the expander. The .open attribute of the expander container returns the current state, which is True if the expander is open and False if it's closed. This lets you skip expensive work when the expander is closed. A callable: The expander tracks state. Streamlit executes the callable as a callback function and reruns the app when the user expands or collapses the expander. The .open attribute of the expander container returns its state like when on_change="rerun". If you need to access the current state inside your callback, fetch it through Session State.  When the expander tracks state, it can't be used inside Streamlit cache-decorated functions. |
   | args | list or tuple or None |  | An optional list or tuple of args to pass to the on_change callback. |
   | kwargs | dict or None |  | An optional dict of kwargs to pass to the on_change callback. |
   | bind | "query-params" or None |  | Binding mode for syncing the expander's expanded state with a URL query parameter. If this is None (default), the expanded state is not synced to the URL. When this is set to "query-params", changes to the expander update the URL, and the expander 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. When bind="query-params" is set, the expander tracks state even if on_change is "ignore" (the default). Toggling still reruns the app, like on_change="rerun", so .open and Session State stay in sync. When the expander's state 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. |

* Returns: ExpanderContainer

    An ExpanderContainer object with an .open property to return
the current state of the expander if the expander tracks state.

* Function signature:

   ```python
   ExpanderContainer
   ```

* Parameters:

   | name | type | default | description |
   |---|---|---|---|
   | open | bool or None |  | Whether the expander is open. This is True if the expander is open, False if it's collapsed, or None if the expander doesn't track state (on_change="ignore" without bind="query-params"). |
