Ship faster with goilerplate templUI Pro

Progress

Progress indicators inform users about the status of ongoing processes.

Source Tailwind CSS JavaScript

Installation

templui add progress

Load the script once in your layout:

<head>
  @progress.Script()
</head>

Examples

Sizes

Variants

Integration Patterns

The Progress component can be integrated in different ways depending on your requirements:

File Uploads

For file uploads, use the browser's XMLHttpRequest or fetch API with progress events:

Multi-step Forms

For multi-step forms, you can use either client-side calculations or HTMX for server-side validation between steps:

// Client-side approach
<div data-current-step="1" data-total-steps="4">
    @progress.Progress(progress.Props{
        Value: 25, // 1 of 4 steps = 25%
        Label: "Step 1 of 4",
        ShowValue: true,
    })
    
    // Form steps
</div>

// HTMX approach
<button 
    hx-get="/form/step/2" 
    hx-target="#form-container"
    class="px-4 py-2 bg-primary text-white rounded"
>
    Next
</button>

Background Processes

For tracking background processes, choose between:

  • HTMX Polling: Simple approach, good for processes under a few minutes

    @progress.Progress(progress.Props{
    	Value: initialValue,
    	Label: "Processing...",
    	ShowValue: true,
    	Attributes: templ.Attributes{
    		"hx-get":     "/api/job/123/progress",
    		"hx-trigger": "every 2s",
    		"hx-target":  "#progress-container",
    	},
    })
  • Server-Sent Events (SSE): For real-time updates and longer processes

    // Server-side Go code
    func SSEHandler(w http.ResponseWriter, r *http.Request) {
    	// Set SSE headers
    	w.Header().Set("Content-Type", "text/event-stream")
    	w.Header().Set("Cache-Control", "no-cache")
    	w.Header().Set("Connection", "keep-alive")
    	
    	// Send progress updates
    	for i := 0; i <= 100; i += 10 {
    		fmt.Fprintf(w, "data: {\"progress\": %d}\n\n", i)
    		w.(http.Flusher).Flush()
    		time.Sleep(1 * time.Second)
    	}
    }

API Reference

Required parameter
Hover for description

Progress

Visual progress indicator component for showing completion status of tasks or processes.

Name Type Default
ID

Unique identifier for the progress element.

string
-
Class

Additional CSS classes to apply to the progress.

string
-
Attributes

Additional HTML attributes to apply to the progress element.

templ.Attributes
-
Value

Current progress value (0-100).

int
0
Max

Maximum value for the progress (defaults to 100 if 0 or negative).

int
0
Size

Size of the progress bar. Options: 'sm', 'lg', or default (empty).

Size
-
Variant

Color variant of the progress bar. Options: 'default', 'success', 'danger', 'warning' (defaults to 'default' if empty).

Variant
-
BarClass

Additional CSS classes to apply to the progress bar itself.

string
-
Label

Optional label text to display above the progress bar.

string
-
ShowValue

Whether to display the progress value as text.

bool
false