Skip to Content
CodeUI

Button

@codeui/styles v0.3.0

A labeled action in plain HTML, styled by variant, size, and ghost attributes.

Load @codeui/styles/button.css, or all.css. The Solid component is documented in Button.

Demo

button/basic.html
<button type="button" class="cui-button" data-cui="button" data-size="sm" data-variant="primary">  Export PNG</button>

Markup

PartElementClassdata-cui
Rootbutton or acui-buttonbutton
Leading iconspancui-button-iconNone
Loading overlaydivcui-loadingNone
AttributeValuesDefault
data-variantprimary, secondary, tertiary, caution, negativeNone. Set one.
data-sizexs, sm, md, lgsm
data-ghostPresenceOff
data-pillPresenceOff
data-blockPresenceOff

Variants

Colors

button/themes.html
<div class="cui-stack" data-direction="row" data-gap="3" data-align="center" data-wrap="true">  <button type="button" class="cui-button" data-cui="button" data-variant="primary">Export PNG</button>  <button type="button" class="cui-button" data-cui="button" data-variant="secondary">Copy snippet</button>  <button type="button" class="cui-button" data-cui="button" data-variant="tertiary">Share snippet</button>  <button type="button" class="cui-button" data-cui="button" data-variant="caution">Overwrite export</button>  <button type="button" class="cui-button" data-cui="button" data-variant="negative">Delete snippet</button></div>

primary uses brand fill. secondary is neutral. tertiary uses soft brand fill. caution and negative use warning and danger colors. Keep one primary action in each group.

Sizes

button/sizes.html
<div class="cui-stack" data-direction="row" data-gap="3" data-align="center" data-wrap="true">  <button type="button" class="cui-button" data-cui="button" data-variant="primary" data-size="xs">Extra small</button>  <button type="button" class="cui-button" data-cui="button" data-variant="primary" data-size="sm">Small</button>  <button type="button" class="cui-button" data-cui="button" data-variant="primary" data-size="md">Medium</button>  <button type="button" class="cui-button" data-cui="button" data-variant="primary" data-size="lg">Large</button></div>

xs, sm, md, and lg are 28px, 36px, 44px, and 52px at comfortable density. Omitting data-size renders sm.

Ghost

button/ghost.html
<div class="cui-stack" data-direction="row" data-gap="3" data-align="center" data-wrap="true">  <button type="button" class="cui-button" data-cui="button" data-variant="secondary" data-ghost>Cancel</button>  <button type="button" class="cui-button" data-cui="button" data-variant="primary" data-ghost>Preview</button>  <button type="button" class="cui-button" data-cui="button" data-variant="negative" data-ghost>Discard</button></div>

data-ghost removes the idle fill. The data-variant colors appear on hover.

Pill

button/pill.html
<div class="cui-stack" data-direction="row" data-gap="3" data-align="center" data-wrap="true">  <button type="button" class="cui-button" data-cui="button" data-variant="primary" data-pill>Export PNG</button>  <button type="button" class="cui-button" data-cui="button" data-variant="secondary" data-pill>Copy snippet</button></div>

Block

button/block.html
<div class="cui-stack" data-gap="2" style="max-width: 360px; margin-inline: auto">  <button type="button" class="cui-button" data-cui="button" data-variant="primary" data-size="md" data-block>Export PNG</button>  <button type="button" class="cui-button" data-cui="button" data-variant="secondary" data-size="md" data-block>Copy snippet</button></div>

data-block sets width to 100% and flex to 1.

Icons

button/icons.html
<div class="cui-stack" data-direction="row" data-gap="3" data-align="center" data-wrap="true">  <button type="button" class="cui-button" data-cui="button" data-variant="secondary">    <span class="cui-button-icon">      <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">        <rect x="8" y="8" width="12" height="12" rx="2" />        <path d="M16 8V4H4v12h4" />      </svg>    </span>    Copy snippet  </button>  <button type="button" class="cui-button" data-cui="button" data-variant="secondary">    Next snippet    <svg class="cui-icon" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">      <path fill-rule="evenodd" d="M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z" clip-rule="evenodd" />    </svg>  </button></div>

Wrap a leading icon in span.cui-button-icon. A trailing icon goes after the label. Give decorative icons aria-hidden="true".

button/as-link.html
<a href="#changelog" class="cui-button" data-cui="button" data-variant="secondary">  Read the changelog</a>

The classes work on an anchor. It keeps link semantics: Enter follows it and Space does not.

States

Disabled

button/disabled.html
<div class="cui-stack" data-direction="row" data-gap="3" data-align="center" data-wrap="true">  <button type="button" class="cui-button" data-cui="button" data-variant="primary" disabled data-disabled>Export PNG</button>  <button type="button" class="cui-button" data-cui="button" data-variant="secondary" disabled data-disabled>Copy snippet</button></div>

Set both disabled and data-disabled. The native attribute removes the button from the tab order and blocks clicks. The dimmed fill selects on data-disabled.

Loading

button/loading.html
<div class="cui-stack" data-direction="row" data-gap="3" data-align="center" data-wrap="true">  <button type="button" class="cui-button" data-cui="button" data-variant="primary" data-loading aria-busy="true" aria-disabled="true">    <div class="cui-loading">      <span class="cui-loading-pointer-group" aria-label="Loading">        <i class="cui-loading-pointer"></i>        <i class="cui-loading-pointer" style="--cui-loading-pointer-delay: 0.2s"></i>        <i class="cui-loading-pointer" style="--cui-loading-pointer-delay: 0.4s"></i>      </span>    </div>    Export PNG  </button></div>

data-loading blocks pointer events and dims the label under three animated dots. The dots are plain markup, so the animation runs without a script. Set aria-busy="true" and aria-disabled="true" yourself, and ignore activation while the work runs.

What you supply

  • Click handlers and form submission.
  • aria-busy and aria-disabled while loading, plus a guard that ignores Enter, Space, and clicks.
  • An accessible name for a button whose only content is an icon. Use IconButton for that case.

Helper

import "@codeui/styles/button.css";
import { applyStyleProps } from "@codeui/styles";
import { buttonStyleProps } from "@codeui/styles/button";

const save = document.querySelector("button")!;
applyStyleProps(save, buttonStyleProps({ variant: "primary", size: "md" }));
// class="cui-button" data-cui="button" data-size="md" data-variant="primary"

On this page