Basic Components
The most frequently used display components: headings, text, buttons, tags, callouts, progress, statistics, loaders, Markdown, syntax highlighting, and more. In each example, the left panel shows the formatted and highlighted TokUI DSL, while the right panel renders it live; click "Edit" to modify it on the fly.
Headings h1 ~ h6
Six-level headings, self-closing. tx is the text (optional — you can write the content inline), v controls alignment and decoration, and bg / fc set the colors.
| Prop | Meaning | Example |
|---|---|---|
tx | Text content (or write content inline) | [h1 标题] |
v | Variant (alignment / decoration, comma-combinable) | v:underline、v:"center,ribbon" |
bg | Background / accent color: theme name (primary/success/warning/danger/dark/light) or 6-digit hex (no #) | bg:success、bg:722ed1 |
fc | Text color (same values as bg) | fc:danger |
id | Element ID (targeted by upd/del/ins) | id:title1 |
Variants: left / center / right (alignment), ribbon, underline, badge / pill. The decorative variants (ribbon/badge/pill/underline) share a "tinted background + accent text" scheme: bg: sets the accent color and the 10% tint background and soft border are derived automatically, adapting to light and dark themes. Without a decorative variant, bg paints a solid full-width background.
Six levels side by side:
Alignment variants:
Decorative variants (recolor with bg):
Solid bg + fc text color, and combining alignment with decoration:
Paragraph p
Body paragraph, dual-mode (same trap as card's tx self-closing): body text present → leaf self-closing; no body text → container collecting children. v controls alignment and weight.
- Leaf mode
[p text]/[p v:bold text]: text is the body; may hold inline children (a/tag/b/strong/em/mark/spin/sub/sup/code); auto-closes on a block sibling. - Container mode
[p]...[/p]: use when placing block children likebtn/form/card; must close with[/p]. - Body text shaped like
word:value(e.g.Q:/A:) is parsed as an attribute (no-space → body empty; with-space → prefix vanishes) — use a full-width:or drop the colon (see DSL syntax).
Variants: left / center / right (alignment), muted, bold, sm / lg (font size).
Link a
Hyperlink, self-closing. u is the URL, tx is the text, and target controls how it opens.
| Prop | Meaning | Example |
|---|---|---|
u | URL | u:https://tokui.jboltai.com |
tx | Text | tx:官网 |
target | Open behavior | target:_blank |
v | Variant | v:underline |
Variants: muted / danger / success / underline.
Divider hr / dv
hr is a plain horizontal rule (self-closing). dv is a divider with text and styling (self-closing).
| Prop | Meaning | Applies to |
|---|---|---|
tx | Divider text | dv |
v | Line style / direction | dv |
bg | Color | dv |
dv variants: dashed / dotted (line style), sm / md / lg (spacing), vert (vertical), plain.
Image img / Gallery imgs
img renders a single image with click-to-zoom lightbox preview. imgs is a container that lays out multiple images in an adaptive grid (up to 3×3).
| Prop | Meaning | Example |
|---|---|---|
s | Image URL | s:https://... |
alt | Alt text | alt:封面 |
w / h | Width / Height | w:120 |
v | Variant | v:avatar |
img variants: avatar, rounded, bordered.
imgs multiple images: pass comma-separated URLs via s, and they are arranged into a 1–9 cell grid automatically.
Preview Group preview-group
Container. Binds a set of img children into a shared preview session: clicking any image opens the lightbox with the whole group's src list (the lightbox supports zoom / rotate / flip / counter / prev-next navigation). Images that arrive later during streaming join the group automatically.
| Prop | Meaning | Example |
|---|---|---|
id | Element ID | id:gallery |
Difference from
imgs:imgsis a shorthand grid layout, whilepreview-groupexpresses the explicit semantics of "one group of images sharing a preview session" — the images keep their normal layout inside.
Kbd kbd
Self-closing inline element. Keycap-styled text for shortcut/operation documentation; works as an inline child of p mixed with text.
Variants: sm / lg.
Float Button float-button
Container. Pins a group of children (btn / backtop, etc.) to a viewport corner; children are automatically rounded into floating action buttons.
| Prop | Meaning | Example |
|---|---|---|
pos | Placement: right-bottom (default) / right-top / left-bottom / left-top | pos:left-top |
offset | Offset from the viewport edge (px, defaults to 24) | offset:80 |
Button btn / Button Group btngroup
btn is self-closing and is the most commonly used interactive component. btngroup is a container that wraps a set of buttons.
| Prop | Meaning | Example |
|---|---|---|
tx | Text | tx:提交 |
clk | Click handler name | clk:onSave |
sub | Form submit handler name | sub:onSubmit |
dis | Disabled | dis |
w | Width | w:200 |
bg / fc | Background / text color | bg:4f46e5 |
t | Native type | t:reset |
v | Variant (type / size / shape) | v:"primary,pill" |
icon | SVG icon name (inherits button color) | icon:view |
i | emoji / character icon | i:🔍 |
l | icon-only label (a11y + hover tooltip) | l:删除 |
Type variants: primary / danger / success / warning / ghost. Size / shape variants: sm / lg / pill (rounded) / square (sharp corners) / block (full-width).
Icon Buttons
Two icon sources, shared by [btn] and the table action column:
icon:NAME— built-in SVG (Lucide-style stroke,stroke=currentColorinherits button color)i:GLYPH— emoji / character (rendered verbatim)
Without tx it becomes an icon-only button: auto-compacted, l: provides the aria-label + hover tooltip.
Icon names: view edit delete add copy download upload refresh check close search setting warn info lock unlock more save export filter sort star link menu
Handlers referenced by
clk:/sub:must be pre-registered viaTokUI.registerHandler(name, fn); the DSL itself never carries executable code.
Tag tag
Labels and categorization, self-closing.
| Prop | Meaning | Example |
|---|---|---|
tx | Text | tx:新功能 |
t | Type / color | t:danger |
s | Size | s:sm |
round | Rounded | round |
closable | Closable | closable |
bordered | Outlined | bordered |
Callout callout
Informational prompt with an icon, self-closing.
| Prop | Meaning | Example |
|---|---|---|
t | Type | t:success |
tt | Title | tt:操作成功 |
tx | Body | tx:已保存 |
Types: info / success / warning / error / tip.
Barcode barcode
Code128 Set B pure-SVG barcode (zero-dependency). Suited for tracking/order/serial numbers — any variable-length alphanumeric data. Scanners auto-detect.
| Prop | Meaning | Example |
|---|---|---|
tx | data to encode (also shown as human-readable text below) | tx:"SF1026883749" |
l / tt | top label | l:"运单号" |
s | size sm/md/lg (default md; accepts small/medium/large) | s:medium |
Visible ASCII only (32–126). Module ratio is preserved (
preserveAspectRatio meet) so scaling stays scannable.
QR Code qrcode
Pure-SVG QR code (matrix generation vendored from qrcode-generator by Arase, MIT; this repo stays zero-npm-dependency). Supports URL / text / UTF-8.
| Prop | Meaning | Example |
|---|---|---|
tx | data to encode (URL/text, UTF-8) | tx:"https://tokui.jboltai.com" |
l / tt | label below | l:"Scan to visit" |
s | size sm/md/lg (default md) | s:md |
ec | error correction L(7%)/M(15%)/Q(25%)/H(30%), default M | ec:H |
Includes a 4-module quiet zone + white background,
shape-rendering=crispEdgesandpreserveAspectRatio=meetto keep modules proportional and scannable when scaled. Higher EC tolerates more damage but is denser.
Status Dot dot
Status indicator, self-closing.
| Prop | Meaning | Example |
|---|---|---|
t | Status type | t:success |
tx | Text | tx:运行中 |
s | Size | s:lg |
pulse | Pulse animation | pulse |
Badge badge / badge-box
badge is a numeric / dot badge (self-closing) that wraps its children. badge-box is a container that attaches a corner badge to its children.
| Prop | Meaning | Applies to |
|---|---|---|
count | Number (parseInt truncates decimals; use tx for versions/decimals) | both |
dot | Dot | both |
tx | Text badge | both (badge-box also accepts legacy label; tx preferred) |
t | Status color (default/primary/success/warning/error) | both |
overflow | Overflow display (e.g. 99+) | both |
pill | Pill (rounded) | badge |
size | Size (sm/lg) | badge |
title | Hover tooltip | badge |
Two ways to badge a heading (h3 is self-closing; never nest [h3 text [badge]]):
- Inline pill (a label beside the title, e.g. a version/status): wrap
h3+badgeinrow v:inline(flex mode). Must usev:inline— the defaultrowis a 12-col grid that squeezes the heading into wrap. - Corner badge (top-right marker, e.g. unread/dot): wrap
h3inbadge-box.
Progress progress
Self-closing. v is the current value (0–100).
| Prop | Meaning | Example |
|---|---|---|
v | Current value | v:60 |
l | Label | l:下载中 |
t | Shape | t:circle |
stripe | Striped | stripe |
status | Status color | status:success |
Shapes: line (default) / circle (ring) / span (inline).
Statistic stat
Data display card, self-closing.
| Prop | Meaning | Example |
|---|---|---|
tt | Label | tt:今日访问 |
v | Value | v:12345 |
pre / suf | Prefix / suffix | suf:% |
trend | Trend | trend:up |
dec | Decimal places | dec:1 |
anim | Number animation | anim |
Countdown countdown
Self-closing. Provide target as a target timestamp or dur as the countdown duration in seconds.
| Prop | Meaning | Example |
|---|---|---|
target | Target time | target:2026-12-31 |
dur | Duration in seconds | dur:3600 |
fmt | Format | fmt:dd天hh:mm:ss |
tx | End text | tx:已结束 |
Loader spin / Skeleton skeleton / Shimmer shimmer
spin is a loading indicator, skeleton is a skeleton screen, and shimmer is a shimmering placeholder. All are self-closing.
| Prop | Meaning | Applies to |
|---|---|---|
t | Type | all three |
s | Size | spin |
tx | Text | spin |
rows | Number of rows | skeleton / shimmer |
Empty State empty / Result Page result
empty is a no-data placeholder and result is an operation result page. Both are self-closing.
| Prop | Meaning | Applies to |
|---|---|---|
tx | Description | both |
icon | Icon | empty |
t | Type | result |
tt | Title | result |
result types: success / error / warning / info.
Copy copy
One-click copy button, self-closing. id points to the target element to copy, or it copies the tx text.
| Prop | Meaning | Example |
|---|---|---|
id | Target element ID | id:codeBlock |
tx | Button text | tx:复制 |
tt | Success toast | tt:已复制 |
Markdown md
Markdown rendering container. Supports common syntax: headings, lists, blockquotes, code, tables, links, and more.
Optional plugin enhancement:
```mermaidfences and$$formula$$/$formula$are enhanced automatically when the host loads thewindow.mermaid/window.katexglobals; without the plugins they fall back to source display (zero-dependency behavior is unaffected, and currency amounts like$5 $6are not mis-parsed).
Formula katex / Diagram mermaid
Standalone component aliases for the md plugin pipeline — declared directly instead of writing md text:
[katex]O(n) = \sum_{i=1}^{n} t_i[/katex]— container, block formula[katex f:"E = mc^2"]—f:attribute, inline formula[mermaid]flowchart LR\n A --> B[/mermaid]— container, diagram source (raw content; inner[is not parsed)
Without katex/mermaid loaded they fall back to source / code block. katex content is exempt from raw escape decoding — write LaTeX commands like \nabla/\times/\to verbatim.
Code Block code
Syntax-highlighted code container. lang specifies the language; the zero-dependency built-in highlighter covers 11 languages: js / ts / python / java / go / rust / sql / html / css / json / bash.
| Prop | Meaning | Example |
|---|---|---|
lang | Language | lang:js |
tx | Title (file name) | tx:app.js |
Inside code content, newlines are encoded as
\n. See the DSL syntax reference for the full prop table.