Components Forms

Radio group

Choose one option from a labeled set.

Live previewGo + HTML
Binding

Usage

Items accepts Label, Value, Description, Checked, and Disabled. Pick at most one initial Checked value. All radios share the same name for native arrow-key navigation and form submission.

Register radio-group with Head and pass its properties to Render. Go setup guide

Go usage
Go usage
err := mono.UI.Render(w, "radio-group", mono.Props{
	"Items": []any{
		map[string]any{
			"Checked":     true,
			"Description": "For short booklets.",
			"Label":       "Saddle stitch",
			"Value":       "stitch",
		},
		map[string]any{
			"Description": "A square spine for longer editions.",
			"Label":       "Perfect bound",
			"Value":       "perfect",
		},
	},
	"Label": "Binding",
	"Name":  "binding",
})
Rendered HTML
Rendered HTML
<fieldset id="demo-radio-group" data-mono="radio-group" class="mu-stack">
  <legend class="mu-label">Binding</legend>
  <label class="mu-row">
    <input type="radio" name="binding" value="stitch" aria-labelledby="demo-radio-group-label-0" aria-describedby="demo-radio-group-hint-0" checked  >
    <span><strong class="mu-label" id="demo-radio-group-label-0">Saddle stitch</strong><span class="mu-small mu-muted" id="demo-radio-group-hint-0">For short booklets.</span></span>
  </label><label class="mu-row">
    <input type="radio" name="binding" value="perfect" aria-labelledby="demo-radio-group-label-1" aria-describedby="demo-radio-group-hint-1"   >
    <span><strong class="mu-label" id="demo-radio-group-label-1">Perfect bound</strong><span class="mu-small mu-muted" id="demo-radio-group-hint-1">A square spine for longer editions.</span></span>
  </label>
</fieldset>
Go template
Go template
<fieldset id="{{.ID}}" data-mono="radio-group" class="mu-stack">
  <legend class="mu-label">{{.Label}}</legend>
  {{range $i,$item := .Items}}<label class="mu-row">
    <input type="radio" name="{{or $.Name $.ID}}" value="{{$item.Value}}" aria-labelledby="{{$.ID}}-label-{{$i}}" {{if $item.Description}}aria-describedby="{{$.ID}}-hint-{{$i}}"{{end}} {{if $item.Checked}}checked{{end}} {{if $item.Disabled}}disabled{{end}} {{if $.Required}}required{{end}}>
    <span><strong class="mu-label" id="{{$.ID}}-label-{{$i}}">{{$item.Label}}</strong>{{if $item.Description}}<span class="mu-small mu-muted" id="{{$.ID}}-hint-{{$i}}">{{$item.Description}}</span>{{end}}</span>
  </label>{{end}}
</fieldset>
Component CSS
Component CSS
[data-mono="radio-group"] { border: 0; padding: 0; min-inline-size: 0; } [data-mono="radio-group"] legend { margin-bottom: .5rem; } [data-mono="radio-group"] input { accent-color: #171717; } [data-mono="radio-group"] .mu-small { display: block; }
Use the HTML in a static site

Copy the rendered HTML above. Download these assets into the same folder as your page, then add the tags below to its head.

Shared CSS Component CSS

HTML head
<link rel="stylesheet" href="./base.css">
<link rel="stylesheet" href="./radio-group.css">

Copy into your project

Run this command from the Mono checkout. Set -out to the component directory in your application.

Terminal
go run ./cmd/mono-ui add -out ./components radio-group
Example properties (JSON)
example.json
{
  "Items": [
    {
      "Checked": true,
      "Description": "For short booklets.",
      "Label": "Saddle stitch",
      "Value": "stitch"
    },
    {
      "Description": "A square spine for longer editions.",
      "Label": "Perfect bound",
      "Value": "perfect"
    }
  ],
  "Label": "Binding",
  "Name": "binding"
}