Skip to main content
The Textbox component creates a text input field for users to enter strings or display string output.

Basic usage

import gradio as gr

def echo(text):
    return text

gr.Interface(fn=echo, inputs=gr.Textbox(), outputs=gr.Textbox()).launch()

Constructor

value
str | Callable | None
default:"None"
Default text to display. If a function is provided, it will be called each time the app loads
type
Literal['text', 'password', 'email']
default:"'text'"
Input type:
  • "text" - Standard text input
  • "password" - Masked password input
  • "email" - Email input with validation
For “password” and “email”, lines must be 1
lines
int
default:"1"
Minimum number of visible lines
max_lines
int | None
default:"None"
Maximum number of visible lines. If None, defaults to max(lines, 20) for text type
placeholder
str | None
default:"None"
Placeholder hint text
label
str | None
default:"None"
Label displayed above the component
info
str | None
default:"None"
Additional info text below the label. Supports markdown/HTML
show_label
bool | None
default:"None"
Whether to display the label
interactive
bool | None
default:"None"
Whether the textbox is editable. Inferred automatically if not provided
visible
bool | Literal['hidden']
default:"True"
Whether the component is visible
autofocus
bool
default:"False"
Whether to focus on the textbox when the page loads
autoscroll
bool
default:"True"
Whether to automatically scroll to bottom when value changes
text_align
Literal['left', 'right'] | None
default:"None"
Text alignment. Only works with type="text"
rtl
bool
default:"False"
Whether to render text right-to-left. Only works with type="text"
max_length
int | None
default:"None"
Maximum character length (including newlines)
submit_btn
str | bool | None
default:"False"
  • True - Show submit button with icon
  • str - Show submit button with custom text
  • False - Hide submit button
stop_btn
str | bool | None
default:"False"
  • True - Show stop button with icon
  • str - Show stop button with custom text
  • False - Hide stop button
buttons
list[Literal['copy'] | Button] | None
default:"None"
List of buttons to show. Options:
  • "copy" - Copy text to clipboard
  • Custom gr.Button() instances

Events

The Textbox component supports the following events:
  • change - Triggered when value changes
  • input - Triggered on every keystroke
  • select - Triggered when text is selected
  • submit - Triggered when Enter is pressed
  • focus - Triggered when component gains focus
  • blur - Triggered when component loses focus
  • stop - Triggered when stop button is clicked
  • copy - Triggered when text is copied

Example with events

import gradio as gr

def handle_change(text):
    return f"You typed: {text}"

with gr.Blocks() as demo:
    textbox = gr.Textbox(label="Enter text")
    output = gr.Textbox(label="Output", interactive=False)
    
    textbox.change(fn=handle_change, inputs=textbox, outputs=output)
    
demo.launch()

Advanced features

Password input

import gradio as gr

def verify_password(password):
    return "✓ Password accepted" if len(password) >= 8 else "✗ Too short"

gr.Interface(
    fn=verify_password,
    inputs=gr.Textbox(type="password", label="Password"),
    outputs=gr.Textbox(label="Status")
).launch()

Multiline text

import gradio as gr

textbox = gr.Textbox(
    lines=5,
    max_lines=10,
    placeholder="Enter multiple lines...",
    label="Long text input"
)

Chat-style interface

import gradio as gr

with gr.Blocks() as demo:
    chatbox = gr.Textbox(
        placeholder="Type a message...",
        submit_btn="Send",
        stop_btn="Stop"
    )
    
demo.launch()