Skip to content
Back to search

gomponents

MarketplaceWorks with Claude CodeGitHub

HTML components in pure Go.

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/maragudk--gomponents/badge.svg)](/listings/maragudk--gomponents)

HTML

<a href="/listings/maragudk--gomponents"><img src="/api/listings/maragudk--gomponents/badge.svg" alt="findsafeskills safety rating" /></a>

Install

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

.claude-plugin/marketplace.json · Manifest · 16 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. {
  2. "name": "gomponents",
  3. "owner": {
  4. "name": "Maragu ApS"
  5. },
  6. "metadata": {
  7. "description": "The gomponents plugin for coding agents."
  8. },
  9. "plugins": [
  10. {
  11. "name": "gomponents",
  12. "source": "./",
  13. "description": "Write HTML in Go with gomponents."
  14. }
  15. ]
  16. }
README.md · README · 198 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. # Tired of complex template languages?
  2. <img src="logo.png" alt="Logo" width="300" align="right">
  3. [![GoDoc](https://pkg.go.dev/badge/maragu.dev/gomponents)](https://pkg.go.dev/maragu.dev/gomponents)
  4. [![CI](https://github.com/maragudk/gomponents/actions/workflows/ci.yml/badge.svg)](https://github.com/maragudk/gomponents/actions/workflows/ci.yml)
  5. [![codecov](https://codecov.io/gh/maragudk/gomponents/branch/main/graph/badge.svg)](https://codecov.io/gh/maragudk/gomponents)
  6. Try HTML components in pure Go.
  7. _gomponents_ are HTML components written in pure Go.
  8. They render to HTML 5, and make it easy for you to build reusable components.
  9. So you can focus on building your app instead of learning yet another templating language.
  10. ```shell
  11. go get maragu.dev/gomponents
  12. ```
  13. Made with ✨sparkles✨ by [maragu](https://www.maragu.dev/): independent software consulting for cloud-native Go apps & AI engineering.
  14. [Contact me at markus@maragu.dk](mailto:markus@maragu.dk) for consulting work, or perhaps an invoice to support this project?
  15. ## Features
  16. Check out [www.gomponents.com](https://www.gomponents.com) for an introduction or [pkg.go.dev/maragu.dev/gomponents](https://pkg.go.dev/maragu.dev/gomponents) for the official docs.
  17. - Build reusable HTML components
  18. - Write declarative HTML 5 in Go without all the strings, so you get
  19. - Type safety from the compiler
  20. - Auto-completion from the IDE
  21. - Easy debugging with the standard Go debugger
  22. - Automatic formatting with `gofmt`/`goimports`
  23. - Simple API that's easy to learn and use (you know most already if you know HTML)
  24. - Useful helpers like
  25. - `Text` and `Textf` that insert HTML-escaped text,
  26. - `Raw` and `Rawf` for inserting raw strings,
  27. - `Map` for mapping data to components and `Group` for grouping components,
  28. - and `If`/`Iff` for conditional rendering.
  29. - No external dependencies
  30. - Mature and stable, no breaking changes
  31. ## Usage
  32. ```shell
  33. go get maragu.dev/gomponents
  34. ```
  35. ```go
  36. package main
  37. import (
  38. . "maragu.dev/gomponents"
  39. . "maragu.dev/gomponents/components"
  40. . "maragu.dev/gomponents/html"
  41. )
  42. func Navbar(authenticated bool, currentPath string) Node {
  43. return Nav(
  44. NavbarLink("/", "Home", currentPath),
  45. NavbarLink("/about", "About", currentPath),
  46. If(authenticated, NavbarLink("/profile", "Profile", currentPath)),
  47. )
  48. }
  49. func NavbarLink(href, name, currentPath string) Node {
  50. return A(Href(href), Classes{"is-active": currentPath == href}, Text(name))
  51. }
  52. ```
  53. (Some people don't like dot-imports, and luckily it's completely optional.)
  54. For a more complete example, see [the examples directory](internal/examples/).
  55. There's also the [gomponents-starter-kit](https://github.com/maragudk/gomponents-starter-kit) for a full application template.
  56. ### Coding agents
  57. There's a [skill](skills/gomponents/SKILL.md) that teaches coding agents how to use gomponents. It's also a good, concise introduction to gomponents for humans. Install it as a plugin:
  58. <details>
  59. <summary>Claude Code</summary>
  60. ```shell
  61. /plugin marketplace add maragudk/gomponents
  62. /plugin install gomponents@gomponents
  63. ```
  64. </details>
  65. <details>
  66. <summary>Codex</summary>
  67. Run these commands from a local clone:
  68. ```shell
  69. codex plugin marketplace add maragudk/gomponents
  70. codex plugin add gomponents@gomponents
  71. ```
  72. </details>
  73. ## Architecture
  74. gomponents is organized into several packages:
  75. - `gomponents`: Core interfaces and functions like `Node`, `El`, `Attr`, and helpers like `Map`, `Group`, `If`, `Text`, `Raw`.
  76. - `gomponents/html`: HTML elements and attributes.
  77. - `gomponents/components`: Higher-level components and utilities.
  78. - `gomponents/http`: HTTP-related utilities for web servers.
  79. - `gomponents/x/...`: Experimental packages. These do not have the same compatibility guarantees as the core library, and in particular, may get breaking changes.
  80. ### Void Elements
  81. Void elements in HTML (like `<br>`, `<img>`, `<input>`) don't have closing tags.
  82. gomponents handles these correctly by checking against an internal list of void elements during rendering.
  83. When you create a void element, any child nodes that are not attributes will be ignored automatically to ensure valid HTML output.
  84. ## FAQ
  85. ### Is gomponents production-ready?
  86. Yes! gomponents is mature, stable, fully tested with 100% coverage, and is used in production by myself and many others, and has been for years.
  87. ### Should I choose `html/template`, Templ, or gomponents?
  88. These are all good choices, and it largely comes down to preference.
  89. I wrote gomponents because I didn't like how I think it's hard to pass data around between templates in `html/template`.
  90. gomponents is pure Go, with no extra build step like Templ, so it works with all tools that already support Go.
  91. That said, both `html/template` and Templ will do the same thing as gomponents in the end. Try them all and choose what you like!
  92. ### Is gomponents fast?
  93. Yes. gomponents renders directly to an `io.Writer`, making it efficient for server-side rendering.
  94. The library avoids unnecessary memory allocations where possible.
  95. There's also an extensive benchmark suite to keep it that way, which you can run with `make benchmark`.
  96. Some highlights from an Apple M4, constructing and rendering to `io.Discard`:
  97. | Benchmark | ns/op | B/op | allocs/op |
  98. |---|---:|---:|---:|
  99. | `El` | 16 | 48 | 1 |
  100. | `Attr`, boolean | 10 | 24 | 1 |
  101. | `Attr`, key-value | 18 | 48 | 1 |
  102. | `Text` | 13 | 16 | 1 |
  103. | `Textf` | 41 | 40 | 2 |
  104. | `Raw` | 3 | 0 | 0 |
  105. | `Rawf` | 36 | 40 | 2 |
  106. | Realistic full page | 63560 | 126580 | 2858 |
  107. ### I don't like how HTML looks in Go.
  108. First of all, that's not a question. 😉
  109. More seriously, think of gomponents like a DSL for HTML. You're building UI components. Give it a day, and it'll feel natural.
  110. ### I'd like to add feature X, can I do that?
  111. First of all, thank you for wanting to contribute! 😊 See [CONTRIBUTING.md](CONTRIBUTING.md) for a guide.
  112. I accept code contributions, especially with new HTML elements and attributes.
  113. I always welcome issues discussing interesting aspects of gomponents, and obviously bug reports and the like.
  114. But otherwise, I consider gomponents pretty much feature complete.
  115. New features to the core library are unlikely to be merged, since I like keeping it simple and the API small.
  116. In particular, new flow control functions (`IfElse`/`Else`) will not be added to the core library.
  117. For generic collection utilities like `Map`, `Filter`, and `Reduce`, see the experimental `x/slices` package.
  118. If there's something missing that you need, I would recommend to keep small helper functions around in your own projects.
  119. And if all else fails, you can always use an [IIFE](https://developer.mozilla.org/en-US/docs/Glossary/IIFE):
  120. ```go
  121. func list(ordered bool) Node {
  122. return func() Node {
  123. // Do whatever you need to do, imperatively
  124. if ordered {
  125. return Ol()
  126. } else {
  127. return Ul()
  128. }
  129. }()
  130. }
  131. ```
  132. ### What's up with the specially named elements and attributes?
  133. Unfortunately, there are some name clashes in HTML elements and attributes, so they need an `El` or `Attr` suffix,
  134. to be able to co-exist in the same package in Go.
  135. I've chosen one or the other based on what I think is the common usage:
  136. - `cite`: `Cite` (element) / `CiteAttr` (attribute)
  137. - `data`: `DataEl` (element) / `Data` (attribute)
  138. - `form`: `Form` (element) / `FormAttr` (attribute)
  139. - `label`: `Label` (element) / `LabelAttr` (attribute)
  140. - `style`: `StyleEl` (element) / `Style` (attribute)
  141. - `title`: `TitleEl` (element) / `Title` (attribute)
  142. Deprecated aliases (`CiteEl`, `DataAttr`, `FormEl`, `LabelEl`, `StyleAttr`, `TitleAttr`) also exist for backwards compatibility but should not be used in new code.

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.