Components Navigation

Pagination

Navigate a server-paginated collection using ordinary links.

Live previewGo + HTML

Usage

Set an Href and a display Label for each page and mark one Current. PrevHref and NextHref are optional, so an end page can omit the unavailable direction.

Register pagination with Head and pass its properties to Render. Go setup guide

Go usage
Go usage
err := mono.UI.Render(w, "pagination", mono.Props{
	"Label":    "Reference pages",
	"NextHref": "/docs/component-templates.html",
	"Pages": []any{
		map[string]any{
			"Href":  "/docs/using-vite.html",
			"Label": "1",
		},
		map[string]any{
			"Current": true,
			"Label":   "2",
		},
		map[string]any{
			"Href":  "/docs/component-templates.html",
			"Label": "3",
		},
	},
	"PrevHref": "/docs/using-vite.html",
})
Rendered HTML
Rendered HTML
<nav data-mono="pagination" id="demo-pagination" aria-label="Reference pages">
  <ul><li><a href="/docs/using-vite.html" rel="prev" class="mu-btn">Previous</a></li>
    <li><a class="mu-btn" href="/docs/using-vite.html" aria-label="Page 1">1</a></li><li><span class="mu-btn mu-primary" aria-current="page" aria-label="Page 2, current">2</span></li><li><a class="mu-btn" href="/docs/component-templates.html" aria-label="Page 3">3</a></li>
    <li><a href="/docs/component-templates.html" rel="next" class="mu-btn">Next</a></li>
  </ul>
</nav>
Go template
Go template
<nav data-mono="pagination" id="{{.ID}}" aria-label="{{.Label}}">
  <ul>{{with .PrevHref}}<li><a href="{{.}}" rel="prev" class="mu-btn">Previous</a></li>{{end}}
    {{range .Pages}}<li>{{if .Current}}<span class="mu-btn mu-primary" aria-current="page" aria-label="Page {{.Label}}, current">{{.Label}}</span>{{else}}<a class="mu-btn" href="{{.Href}}" aria-label="Page {{.Label}}">{{.Label}}</a>{{end}}</li>{{end}}
    {{with .NextHref}}<li><a href="{{.}}" rel="next" class="mu-btn">Next</a></li>{{end}}
  </ul>
</nav>
Component CSS
Component CSS
[data-mono="pagination"] ul { display:flex; align-items:center; flex-wrap:wrap; gap:.3rem; margin:0; padding:0; list-style:none; }
[data-mono="pagination"] .mu-btn { min-width:2.15rem; justify-content:center; }
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="./pagination.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 pagination
Example properties (JSON)
example.json
{
  "Label": "Reference pages",
  "NextHref": "/docs/component-templates.html",
  "Pages": [
    {
      "Href": "/docs/using-vite.html",
      "Label": "1"
    },
    {
      "Current": true,
      "Label": "2"
    },
    {
      "Href": "/docs/component-templates.html",
      "Label": "3"
    }
  ],
  "PrevHref": "/docs/using-vite.html"
}