> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/gradio-app/gradio/llms.txt
> Use this file to discover all available pages before exploring further.

# DownloadButton

> Allow users to download files

The DownloadButton creates a button that downloads a file when clicked.

## Basic usage

```python theme={null}
import gradio as gr

def get_file():
    return "output.txt"

with gr.Blocks() as demo:
    download = gr.DownloadButton("Download File", value="output.txt")
    
demo.launch()
```

## Constructor

<ParamField path="label" type="str" default="'Download'">
  Button label text
</ParamField>

<ParamField path="value" type="str | Path | Callable | None" default="None">
  Filepath or URL to download. Can be a function that returns the path
</ParamField>

<ParamField path="variant" type="Literal['primary', 'secondary', 'stop']" default="'secondary'">
  Button style variant
</ParamField>

<ParamField path="size" type="Literal['sm', 'md', 'lg']" default="'lg'">
  Button size
</ParamField>

## Events

* **click** - Triggered when button is clicked

## Examples

### Dynamic download

```python theme={null}
import gradio as gr

def create_report(data):
    # Generate report file
    with open("report.txt", "w") as f:
        f.write(data)
    return "report.txt"

with gr.Blocks() as demo:
    input_data = gr.Textbox(label="Data")
    download = gr.DownloadButton("Download Report")
    
    input_data.change(
        fn=create_report,
        inputs=input_data,
        outputs=download
    )
    
demo.launch()
```

### Primary button

```python theme={null}
import gradio as gr

download = gr.DownloadButton(
    "Download Results",
    value="results.csv",
    variant="primary"
)
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.