Controls, forms, and layouts

Turn any Kiki page into an interactive tool with state inputs, validated field forms, button actions, and row, col, and grid layouts.

Session state controls

Wrap a default value in state to give each viewer their own interactive input without modifying the .ki file. Reloading restores the default. Definitions (=) stay silent—place a control wherever you want it to appear with input (bare) or field (labelled):

> max-rows = state 3

> title = state "Untitled"

> agree = state (toggle false)

> row [(field "Max rows" max-rows) (field "Title" title) (field "Agree" agree)]

state picks a control from the default's type (:bool checkbox, :date picker, :string or number input), or takes an explicit control decorator such as toggle, slider, or choice:

> limit = state ((slider 0 60 5) 25)

> plan = state ((choice ["free" "plus" "pro"]) "free")

> row [(input limit) (input plan)]

> "\(title): \(plan) plan (up to \(limit))"

"Untitled: free plan (up to 25)"

choice accepts either a literal list or a column from a table (choice clients.Name). Because input and field return ordinary :view values, you can also show a control conditionally:

Toggle Agree above to show the Row limit slider.

Toggle Agree above to show the Row limit slider.

Source controls

Without state, a control edits its literal value directly in the .ki file—toggling dark rewrites false to true in source, which is useful for persistent checklists or saved page drafts. Named source controls place with input and field just like state; inline controls like \(toggle false) work directly inside prose:

> dark = toggle false

> due = date-picker 2026-08-15

> row [(field "Dark mode" dark) (field "Due" due)]

> if dark -> "Lights on until \(due)" else -> "Daylight mode"

"Daylight mode"

Forms

field label control places any control with a label, and hint text view adds optional help text beneath it. required blocks a button's task when a state input is still empty and shows its message on the field:

> email = required "Enter an email." (state "")

> notes = state (long-text "Deliver to the side door.")

> hint "Where we send the receipt." (field "Work email" email)

Where we send the receipt.

> field "Notes" notes

Use long-text for multi-line plain text inputs, or rich-text ~ for formatted document blocks (doc/markup.ki).

Buttons

button label task runs side-effecting work (table.insert, table.update, table.delete, write-file, files.open) only when clicked. Pass a list of tasks to run several steps in order:

> save = button "Save note" (write-file "note.txt" (io.encode notes))

Wrap a button in confirm to ask first, or enabled to require a condition and explain why it is disabled:

> reset = confirm "Clear and start over?" (tag "danger" (button "Reset" (print "reset")))

> submit = enabled agree "Accept the terms first."

(tag "primary" (button "Submit" (print "submitted")))

> row [submit reset]

Layout

Views—prose, controls, buttons, tables, and charts—compose with row, col, grid n, metric, callout, and tag:

> grid 3 [

(metric "Open tasks" (~ 12))

(metric "Due today" (~ 3))

(metric "Completion" (0.75 |> (format.percent 0)))]

Open tasks

12

Due today

3

Completion

75%

> grid 2 [

(tag "card" (col [(heading 3 ~ Draft) (dim ~ Ready to review) save]))

(tag "card" (col [(heading 3 ~ Sent) (dim ~ Nothing sent today)]))]

Draft

Ready to review

Sent

Nothing sent today

Common theme tags are "card", "ruled", "hero", "primary", and "danger".

Document context

set configures how a page opens and renders; with overrides context for a single block or expression.

• view: 'tool opens in Use mode (prose locked and code hidden while controls, buttons, and editable tables stay live); 'page opens in Edit mode (a clean document whose code unfolds when clicked); 'code (the default) shows every cell's code.

• mode: 'result, 'source, or 'source-result controls whether blocks show their output, code, or both (> set {view = 'page mode = 'source-result}).

• timezone: 'local, 'utc, or an IANA zone name.

• today: > set today = 2026-10-30 pins io.today and io.now for reproducible examples (automatically stripped when copied into a workspace).

> context.timezone

'utc

Where next

• doc/build.ki — combine tables, forms, buttons, and metrics into a tool

• doc/table.ki — editable table columns, key, owner, view.board, and view.calendar

• doc/program.ki — Task values, file I/O, and CLI programs