Show API reference for

Display a link button element.

When clicked, a new tab will be opened to the specified URL. This will create a new session for the user if directed within the app.

Function signature[source]

st.link_button(label, url, *, key=None, on_click="ignore", args=None, kwargs=None, help=None, type="secondary", icon=None, icon_position="left", disabled=False, use_container_width=None, width="content", shortcut=None)

Parameters

label (str)

A short label explaining to the user what this button is for. 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.

url (str)

The URL to open on user click.

key (str, int, or None)

An optional string to use for giving this element a stable identity. If this is None (default), the element's identity will be determined based on the values of the other parameters.

If on_click enables widget behavior and key is provided, Streamlit will register the key in Session State to store the button state. The button state is read-only. For more details, see Widget behavior.

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

on_click (callable, "rerun", or "ignore")

How the button should respond to user interaction. This controls whether or not the button behaves like an input widget. This can be one of the following values:

  • "ignore" (default): Streamlit opens the link in a new tab and doesn't rerun the app. The button won't behave like an input widget.
  • "rerun": Streamlit opens the link in a new tab and reruns the app. In this case, st.link_button returns a Boolean value like st.button.
  • A callable: Streamlit opens the link in a new tab, reruns the app, and executes the callable at the beginning of the rerun. In this case, st.link_button returns a Boolean value.

args (list or tuple)

An optional list or tuple of args to pass to the callback when on_click is a callable. If on_click isn't a callable, this is ignored.

kwargs (dict)

An optional dict of kwargs to pass to the callback when on_click is a callable. If on_click isn't a callable, this is ignored.

help (str or None)

A tooltip that gets displayed when the button is hovered over. If this is None (default), no tooltip is displayed.

The tooltip can optionally contain GitHub-flavored Markdown, including the Markdown directives described in the body parameter of st.markdown.

type ("primary", "secondary", or "tertiary")

An optional string that specifies the button type. This can be one of the following:

  • "primary": The button's background is the app's primary color for additional emphasis.
  • "secondary" (default): The button's background coordinates with the app's background color for normal emphasis.
  • "tertiary": The button is plain text without a border or background for subtlety.

icon (str or None)

An optional emoji or icon to display next to the button label. 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 (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.

icon_position ("left" or "right")

The position of the icon relative to the button label. This defaults to "left".

disabled (bool)

An optional boolean that disables the link button if set to True. The default is False.

use_container_width (bool)

delete

use_container_width is deprecated and will be removed in a future release. For use_container_width=True, use width="stretch". For use_container_width=False, use width="content".

Whether to expand the button's width to fill its parent container. If use_container_width is False (default), Streamlit sizes the button to fit its contents. If use_container_width is True, the width of the button matches its parent container.

In both cases, if the contents of the button are wider than the parent container, the contents will line wrap.

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

The width of the link button. This can be one of the following:

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

shortcut (str or None)

An optional keyboard shortcut that triggers the button. This can be one of the following strings:

  • A single alphanumeric key like "K" or "4".
  • A function key like "F11".
  • A special key like "Enter", "Esc", or "Tab".
  • Any of the above combined with modifiers. For example, you can use "Ctrl+K" or "Cmd+Shift+O".

Important

The keys "C" and "R" are reserved and can't be used, even with modifiers. Punctuation keys like "." and "," aren't currently supported.

For a list of supported keys and modifiers, see the documentation for st.button.

Returns

(element or bool)

If on_click is "ignore" (default), this command returns an internal placeholder for the button element. Otherwise, this command returns a Boolean value in the same manner as st.button: True if the button was clicked on the last rerun and False if it wasn't.

Examples

import streamlit as st

st.link_button("Go to gallery", "https://streamlit.io/gallery")
forum

Still have questions?

Our forums are full of helpful information and Streamlit experts.