st.link_button
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:
|
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:
|
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:
|
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:
|
shortcut (str or None) | An optional keyboard shortcut that triggers the button. This can be one of the following strings:
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")
Still have questions?
Our forums are full of helpful information and Streamlit experts.