Skip to main content
The Button component creates a clickable button that triggers events.

Basic usage

import gradio as gr

def greet():
    return "Hello!"

with gr.Blocks() as demo:
    output = gr.Textbox()
    btn = gr.Button("Click me")
    btn.click(fn=greet, outputs=output)
    
demo.launch()

Constructor

value
str | Callable
default:"'Run'"
Button label text
variant
Literal['primary', 'secondary', 'stop', 'huggingface']
default:"'secondary'"
Button style:
  • "primary" - Main call-to-action
  • "secondary" - Subdued style
  • "stop" - Stop button
  • "huggingface" - HF branded style
size
Literal['sm', 'md', 'lg']
default:"'lg'"
Button size
icon
str | Path | None
default:"None"
URL or path to icon file to display
URL to open when clicked
Where to open the linked URL
interactive
bool
default:"True"
Whether button is clickable

Events

  • click - Triggered when button is clicked

Examples

Primary button

import gradio as gr

btn = gr.Button("Submit", variant="primary")

With icon

import gradio as gr

btn = gr.Button(
    "Download",
    icon="https://huggingface.co/favicon.ico"
)
import gradio as gr

btn = gr.Button(
    "Visit Gradio",
    link="https://gradio.app",
    link_target="_blank"
)