Skip to content

Build UI / Components / Button

Button ​

A button triggers a synchronous action owned by the page it's on — form submission, form reset, or a clicked event other elements subscribe to. It never changes the URL. If the outcome is a new location, wire <kb-redirect> to the button's clicked event instead of putting that logic in the button.

preview
Code
html
<kb-button>Save</kb-button>
<kb-button variant="naked">Cancel</kb-button>
<kb-button variant="link">Learn more</kb-button>
<kb-button color="danger">Delete</kb-button>

Usage ​

html
<kb-button type="submit" color="primary">Save</kb-button>
js
document.querySelector('kb-button').addEventListener('clicked', (event) => {
  console.log(event.detail) // the button's `value`
})

When to use ​

  • Submitting or resetting a <form> (type="submit" / type="reset").
  • Triggering an action local to the page — opening a dialog, adding a row, deleting a record — where the response is a clicked event, not a URL change.

When not to use ​

  • Navigating to another route or URL. Use a plain <a> for external or full-page navigation, or <kb-redirect> wired to a button's clicked event for in-app navigation. kb-button has no concept of a destination.

Disabled ​

disabled blocks focus, click, and form submission — it's written onto the inner <button>, so keyboard activation is blocked by the platform, not by kb-button's own code. A button also picks up disabled from an enclosing <fieldset disabled>, without setting the attribute itself.

preview
Code
html
<kb-button disabled>Save</kb-button>

<fieldset disabled>
  <legend>Account</legend>
  <kb-button>Save</kb-button>
</fieldset>

Variants ​

variant expresses emphasis, not decoration — pick by how important the action is relative to its siblings, not by taste.

preview
Code
html
<kb-button variant="solid">Solid</kb-button>
<kb-button variant="naked">Naked</kb-button>
<kb-button variant="ghost">Ghost</kb-button>
<kb-button variant="link">Link</kb-button>
<kb-button variant="icon"><kb-icon use="home"></kb-icon></kb-button>
VariantEmphasisUse for
solid (default)HighestThe one primary action in an area. More than one per area and neither reads as primary.
nakedMediumA secondary action next to a solid one — "Cancel" beside "Save".
ghostMedium-lowAn action inside a filled surface, where a bordered button would compete with it.
linkLowestAn action that reads like a text link — inline in prose or a table cell.
iconCompactIcon-only, where space is constrained. Always give it an accessible name.

Color ​

color carries meaning; it isn't a styling knob.

preview
Code
html
<kb-button color="primary">Primary</kb-button>
<kb-button color="danger">Delete</kb-button>
<kb-button color="success">Confirm</kb-button>
<kb-button color="warning">Review</kb-button>
  • primary — the default, for ordinary actions.
  • danger — reserved for destructive or hard-to-undo actions. Not for emphasis.
  • master, complete, success, warning, info, menu — only when the outcome genuinely matches that semantic.

Width ​

width controls how the button fills its container, not its visual weight.

preview
Code
html
<div style="width: 100%">
  <kb-button width="fill">Continue</kb-button>
</div>
  • auto (default) — hugs the label; use inline, next to other content.
  • fill — spans the container; for a single full-width action.
  • hug — explicit synonym for auto.
  • A px/% value — only when a spec demands it. A fixed width doesn't adapt to a translated label.

Composition ​

  • Can contain: plain text (the label), <kb-icon> for icon-only or icon+label buttons, and one or more <kb-on> for extra arcs beyond the single on attribute. Anything else still renders, but slotted content gets pointer-events: none, so it can't intercept the click meant for the button.
  • Can be a child of: anything. Commonly inside <kb-form> as the submit control, inside <kb-card>, or standalone.
preview
Code
html
<kb-button>
  <kb-icon use="download"></kb-icon>
  Download
</kb-button>

Content ​

The label should be a short, specific verb phrase — "Save", "Delete file", "Add row" — not a vague "OK" or "Submit". Long labels wrap rather than truncate; the button doesn't clip text.

Attributes ​

AttributeTypeDefaultDescription
altstring''Accessible name, written as aria-label onto the inner <button>. Required for variant="icon". Escaped before it's interpolated, so it can't break out of the attribute.
colormaster | primary | complete | success | warning | danger | info | menuprimarySemantic color, resolved against --color-{value}. An unrecognized value is ignored — the property keeps the last valid color it had.
disabledbooleanfalseBlocks focus, click, and form submission. Also set when the button sits inside a <fieldset disabled>.
variantsolid | naked | ghost | link | iconsolidEmphasis level. An unrecognized value is ignored — the property, and the :state(...) it drives, keep the last valid variant.
widthauto | fill | hug | lengthautoHow the button fills its container.
typesubmit | reset | buttonsubmitBehavior inside an owning <form>: submit requests submission, reset resets it, button does neither. An unrecognized value is ignored — the property keeps the last valid type.
valuestring—Payload dispatched as the clicked event's detail and along on arcs. Not a form submission value — kb-button never calls setFormValue(), so value never reaches FormData. Give the button a name on the surrounding form field or distinguish actions by their clicked listener instead.
hiddenbooleanfalseRemoves the button from layout and the accessibility tree.
onarc string—Echo wiring, source/event:type/sink.

Methods ​

MethodDoesReturns
click()Runs the same form interaction as a real click — submits or resets the owning form according to type — then dispatches clicked.the element itself, for chaining

Events ​

EventFires whendetail
clickedthe button is activated — by click, Enter while focused, or a call to click()the value attribute

type="submit" runs the form's native constraint validation before submitting: a required field left empty blocks both the submit event and clicked the same way a native <button type="submit"> would. Outside a <form>, type="submit"/type="reset" have nothing to act on — clicked still fires.

Styling ​

Every visual decision is a --button-* custom property defaulting to a global token. Custom properties inherit through the shadow boundary, so set them on the element or any ancestor — never reach into the shadow DOM.

For anything the custom properties don't cover, the inner <button> exposes part="button", reachable with kb-button::part(button).

Custom propertyDefaultControls
--button-color-accentvar(--color-{color})Accent filling solid and coloring text/border of the rest.
--button-color-textvar(--color-pure-white)Label color on solid.
--button-color-background-ghostvar(--color-master-lighter)Background of ghost.
--button-font-familyvar(--font-family-base)Label typeface.
--button-font-sizevar(--font-size-xxs)Label size.
--button-font-weightvar(--font-weight-medium)Label weight.
--button-line-heightvar(--line-height-default)Label line height.
--button-letter-spacing0.38pxLabel tracking.
--button-size-height40pxHeight, and the square side of icon.
--button-size-min-width40pxMinimum width, so short labels stay tappable.
--button-space-inlinevar(--spacing_inset-xs)Horizontal padding.
--button-space-gapvar(--spacing_inset-nano)Gap between label and slotted icon.
--button-border-widthvar(--border-width-thin)Border thickness.
--button-border-radiusvar(--border-radius-sm)Corner radius.
--button-transitionall 0.2s ease-outTransition on interaction.
preview
Code
html
<div class="checkout" style="--button-size-height: 56px; --button-border-radius: 500px; --button-font-size: 16px;">
  <kb-button>Checkout</kb-button>
</div>

States and accessibility ​

  • hidden removes the button from layout and interaction. Prefer it over not rendering the element when the presence or absence should stay findable in the DOM.
  • disabled removes the button from the tab order and blocks click and form submission. It's enforced by the native disabled attribute on the inner <button>, so keyboard and pointer activation are both blocked by the platform.
  • An icon button needs alt. The glyph conveys nothing, and without a name the button is announced from the ligature text — <kb-button variant="icon" use="cloud_upload"> reads as "cloud_upload". alt is written as aria-label onto the <button> in the shadow root, which is what the accessibility tree treats as the button — the host only wraps it.
  • Leave alt unset on a button with visible text — the text already names it, and a differing alt would make the announced name diverge from the written one, breaking voice control.
  • type="submit"/type="reset" only interact with an owning <form>. Standalone, there's no form to submit or reset — clicked still fires.
  • Tab delegates focus straight to the inner <button> (delegatesFocus: true) — there's no separate host-level focus stop. Enter while focused activates it, the same as clicking.

Do's and don'ts ​

DoDon't
Use exactly one solid button per area for the primary actionPut two solid buttons side by side — neither reads as primary
Reserve color="danger" for destructive actionsUse danger just to make a button stand out
Give an icon-only button an accessible nameShip an icon-only button with no label for assistive tech
Use width="fill" for the single action in a narrow formFix width in px for a label that can grow when translated
Set type="button" on an in-form action that shouldn't submitLeave type unset on that button — the default is submit, so it submits the form