Getting Started
Core Concepts
Control
Interactivity
Performance
Pushing Data
HTMX Extensions
Miscellaneous
Configuration
Tags and Attributes
In htmgo, html is built using a set of functions that return *h.Element.
These functions are all defined in the 'h' package in htmgo/framework
htmgo provides methods to render most if not all html tags and attributes.
Example:
1h.Div(
2 h.Class("flex gap-2"),
3 h.Button(
4 h.Text("Submit"),
5 ),
6)
All methods can be found in the 'h' package in htmgo/framework
h.Tag and h.Attribute are available to use when you need to render a tag or attribute that htmgo does not provide a method for.
1h.Tag("my-custom-tag",
2 h.Class("flex gap-2"),
3 h.Button(
4 h.Attribute("x-custom-attr", "my-value"),
5 h.Text("Submit"),
6 ),
7)
Attributes are one of the main ways we can add interactivity to the pages with htmx.
htmgo provides various methods to add attributes to elements, as well as adding attributes based on a condition.
1h.Div(
2 h.Class("flex gap-2"),
3 h.Id("my-div"),
4 h.If(
5 error != "",
6 h.Class("p-4 bg-rose-400 text-white rounded"),
7 )
8)
Example using htmx attributes:
1h.Tr(
2 h.Class("flex gap-2"),
3 h.HxInclude("input")
4 h.Td(
5 h.Input("text",
6 h.Class("p-4 rounded"),
7 h.Placeholder("Type something"),
8 h.Name("my-input"),
9 )
10 ),
11 h.Td(
12 h.Button(
13 h.Text("Submit"),
14 )
15 ),
16)