---
title: "oneui for Go"
url: https://recursiveai.org/oneui/go/
description: "A UI component library for Go. Components are an HTML template, optional scoped CSS and a Go struct, compiled by go generate into code that updates only the nodes bound to changed state. Render to HTML, run in the browser with WebAssembly, test without a browser. No dependencies. MIT or Apache-2.0."
---

# oneui for Go

A free, open-source UI component library for Go, MIT or Apache-2.0. A component is an HTML template, optional scoped CSS and a Go struct; `go generate` compiles it into plain Go that updates only the nodes bound to state that changed.

Render it to HTML, run it in the browser with WebAssembly, or test it without a browser. No dependencies: its `go.mod` requires nothing.

```sh
go get recursiveai.org/go/oneui@v1.0.1
```

- [Getting started](https://recursiveai.org/oneui/go/docs/getting-started/)
- [Docs](https://recursiveai.org/oneui/go/docs/)
- [GitHub](https://github.com/recursive-ai-oss/oneui-go)
- [pkg.go.dev](https://pkg.go.dev/recursiveai.org/go/oneui)

## Quick start

The README’s quick start, run with Go 1.26.8 against v1.0.1 from the module proxy. `go generate` writes `SetCount` and the code that rewrites only the button’s text when `Count` changes.

[Tests, lists and the browser](https://recursiveai.org/oneui/go/docs/getting-started/)

*Hello.html · HTML*

```
<button on:click="Increment">Clicked {Count} times</button>
```

*main.go · Go*

```
package main
 
//go:generate go run recursiveai.org/go/oneui/cmd/oneui generate
 
import (
    "os"
 
    "recursiveai.org/go/oneui"
)
 
type Hello struct {
    oneui.Base
    Count int `oneui:"state"`
}
 
func (h *Hello) Increment() { h.SetCount(h.Count + 1) }
 
func main() {
    h := &Hello{}
    h.Increment()
    oneui.RenderHTML(os.Stdout, h)
}
```

*Shell · sh*

```
go mod init example.com/hello
go get recursiveai.org/go/oneui@v1.0.1
go generate ./...
go run .
```

*Output · Go 1.26.8*

```
<button>Clicked 1 times</button>
```

## Fixed in 1.0.1

- **Submit buttons**: In the reference document, “a click on a submit button […] now submits its form owner: the form’s `submit` event is raised, bubbles, and can be cancelled, as in the HTML Standard.” A `required` control without a value blocks submission unless the submitter has `formnovalidate` or the form has `novalidate`.
- **Enter key**: “Enter in a text-like field submits implicitly.” “Enter or Space on a focused submit button, and a click on a label for one, submit too.”
- **Browser**: In the browser backend, “forms submit natively, so handlers see the browser’s own `submit` event once”, and “a form with `on:submit` no longer reloads the page.”
- **Tests**: Added `oneuitest.Page.Press(selector, key)`.

- [Changelog](https://recursiveai.org/oneui/go/docs/changelog/)
- [CHANGELOG.md at v1.0.1](https://github.com/recursive-ai-oss/oneui-go/blob/v1.0.1/CHANGELOG.md)

## Speed

The repository’s benchmark: a list of 1,000 rows written three ways, each checked to produce the same markup first. Median time per operation of six counts on an AMD Ryzen 9 7950X3D with Go 1.26.8 on Linux.

[What each row measures](https://github.com/recursive-ai-oss/oneui-go/blob/v1.0.1/bench/METHOD.md)

| Row | oneui | templ | go-app |
|---|---|---|---|
| Render to HTML | 28.3 µs | 537 µs | 1.11 ms |
| Mount to change set, cold | 736 µs | not a job templ does | tree build 687 µs |
| Update one row, live (change set) | 13.9 µs | no live update | wasm only |
| Update one row, server-side re-render | 29.1 µs | 471 µs | 1.08 ms (render function only) |
| Update every row, server-side re-render | 29.5 µs | 500 µs | 1.18 ms |

> Mounting a cold context to a change set takes 736 µs against go-app’s element-tree build at 687 µs, 7% slower, with 38% fewer allocations; warm (a long-lived context) it is 575 µs, ahead.
>
> [bench/RESULTS.md at v1.0.1](https://github.com/recursive-ai-oss/oneui-go/blob/v1.0.1/bench/RESULTS.md)

## What it does

- **Version**: oneui v1.0.1. Go 1.24 or newer.
- **Templates**: `oneui generate`, run from `//go:generate`, compiles each template into plain Go. Templates have text and attribute bindings, events, two-way `bind:value`, `class:` toggles, `if`/`else` and keyed `each`, with optional scoped CSS. A name the struct doesn’t have is reported as `file:line:col`.
- **State**: A field tagged `oneui:"state"` gets a setter, and changing it rewrites only the nodes bound to it. Nothing is diffed and nothing is reflected.
- **Change sets**: Components write every mutation as a backend-neutral change-set stream, in JSON or a compact binary form. The decoders treat input as untrusted and bound its sizes.
- **Backends**: `RenderHTML` writes the markup for first paint or server-side rendering (no hydration). Package `browser` runs components in a web page through `GOOS=js GOARCH=wasm` as custom elements. Any other sink, such as a native document, applies the same stream.
- **Tests**: Package `oneuitest` mounts a component in the reference DOM, with selector and accessibility queries and a manual clock: `Mount`, `Click`, `Type`, `Press`, `Text`, no browser.
- **UI tree**: Package `ui` is an engine-free retained UI tree with CSS-model styles, flexbox layout, input and focus, tweens and a display list for a host to paint. `ui/kit` adds buttons, toggles, sliders, dropdowns, tabs, dialogs, lists, tables, scroll views and text inputs, with a light and a dark theme.
- **Hot reload**: In a program built with the `oneui_reload` tag, an edited template that uses only expressions, handlers and components the build already has replaces the running one in place: the component keeps its state, typed text, focus and scroll position. Anything else asks for a rebuild and leaves the component as it was.
- **Dependencies**: None. The module’s `go.mod` requires nothing.
- **License**: MIT or Apache-2.0, at your choice.
