Skip to content

Hover, focus and other states

Prefix a utility with a variant to apply it conditionally.

Variants such as hover:, focus-visible: and active: apply a utility only while that state holds. Interaction state comes from the previous frame’s hit testing, so there is no event wiring to write.

Hover, focus and other states: Hover, focus and other statesHover, focus and other states: Hover, focus and other states
ui.button("Save changes", "rounded-full bg-violet-500 px-5 py-2 text-sm font-semibold text-white transition hover:bg-violet-600 active:scale-95 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-violet-500")

Mark a parent with group and style children with group-hover: and friends.

Hover, focus and other states: Group statesHover, focus and other states: Group states
if ui.button_box("group block w-full max-w-xs rounded-lg bg-white p-6 shadow-lg ring-1 ring-gray-900/5 transition hover:bg-sky-500 hover:ring-sky-500 dark:bg-white/5 dark:ring-white/10") {
if ui.div("flex items-center gap-3") {
ui.icon(IC.bolt, "size-6 text-sky-500 group-hover:text-white")
ui.text("New project", "text-sm font-semibold text-gray-900 group-hover:text-white dark:text-white")
}
ui.text("Create a new project from a variety of starting templates.", "mt-2 text-sm text-gray-500 group-hover:text-white dark:text-gray-400")
}
Hover, focus and other states: First, last, odd and evenHover, focus and other states: First, last, odd and even
if ui.div("w-full max-w-sm divide-y divide-gray-200 overflow-hidden rounded-lg ring-1 ring-gray-200 dark:divide-white/10 dark:ring-white/10") {
for name in ([]string{"Kristen Ramos", "Floyd Miles", "Courtney Henry", "Ted Fox"}) {
ui.text(name, "px-4 py-3 text-sm text-gray-700 odd:bg-white even:bg-gray-50 dark:text-gray-300 dark:odd:bg-white/5 dark:even:bg-transparent")
}
}

Pass {.Selected}, {.Checked}, {.Disabled} or {.Open} flags to light up aria-selected:, checked:, disabled: and open: variants from your own state.

Hover, focus and other states: Application stateHover, focus and other states: Application state
tab := &s.demo.tab
if ui.div("flex gap-1 rounded-lg bg-gray-100 p-1 dark:bg-white/5") {
for label, i in ([]string{"Overview", "Activity", "Settings"}) {
ui.key(label)
if ui.button(label, "rounded-md px-3 py-1.5 text-sm font-medium text-gray-600 transition hover:text-gray-950 aria-selected:bg-white aria-selected:text-gray-950 aria-selected:shadow-sm dark:text-gray-400 dark:hover:text-white dark:aria-selected:bg-white/10 dark:aria-selected:text-white", i == tab^ ? {.Selected} : {}) {
tab^ = i
}
}
}