---
description: Attribute-based CSS skins for buttons, form inputs, field groups, cards,
  badges, avatars, status indicators, and data tables.
output-file: controls.html
title: Controls and feedback

---
<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

AnswerUI applies component styles through HTML attributes such as `[btn]`, `[input]`, and `[card]`, keeping native focus, keyboard activation, form submission, and validation intact. Add `[btn]` to an `<a>` element to style a link like a button without changing its navigation semantics. Omit `[btn]` on ordinary links to keep default link styling.

```python
from answerui.preview import preview
```

## Buttons

Add `[btn]` to a `<button>` or `<a>` for a primary accent button with `--bevel` and `--raised` shadows. Set `btn-variant="secondary"` for a bordered `--color-surface` button, or `btn-variant="quiet"` for a transparent button that highlights on hover. Set `btn-variant="editable"` for a full-width, dashed-border trigger with a text cursor for click-to-edit values. Change button size with `btn-size="sm"` or `btn-size="lg"`, and add `[btn-icon]` for square icon-only buttons.

Setting `aria-pressed="true"` or `aria-expanded="true"` switches a button to `--ui-held-face` and `--ui-held-shadow` (`--bevel-in` and `--sunken` on primary and secondary buttons). Adding `disabled` lowers opacity to 50% and removes the shadow. The CSS never binds click handlers, toggles ARIA attributes, or turns a button into a link. Wrapper components default to `type="button"`, whereas plain `<button btn>` elements follow native form defaults. On `[btn][copy]` and `[btn][copyfor]`, setting `[copied]` swaps the first `<svg><use>` icon for the second.

Setting `aria-busy="true"` hides child `span` and `svg` elements and shows a centred spinner immediately. With HTMX's `.htmx-request` class, the same busy state appears after `--busy-delay` (default `200ms`). Fast requests finish before the spinner appears. Under `prefers-reduced-motion: reduce`, button transitions are disabled and the spinner slows to `2s`.

```python
preview('''
<section card stack>
  <div cluster>
    <button type="button" btn>Save</button>
    <a href="#options" btn btn-variant="secondary">Options</a>
    <button type="button" btn btn-variant="quiet">Dismiss</button>
  </div>
  <div cluster>
    <button type="button" btn aria-pressed="true">Pinned</button>
    <button type="button" btn ui-tone="danger">Delete</button>
    <button type="button" btn disabled>Unavailable</button>
    <button type="button">Native</button>
  </div>
</section>
''', height='12rem')
```

## Form controls, fields, and groups

Add `[input]`, `[textarea]`, or `[select]` for full-width sunken fields; add `[chars]` with `--ui-chars` to size a control to its expected character width (`--bevel-in` and `--sunken` on `--color-background`); `[input]` also works on a container such as `<div input>` for mounted third-party inputs (for example, Stripe Elements). Browser spin buttons are hidden on `[input][type="number"]`. `[textarea]` starts at `5rem` high, resizes vertically, and grows with its content via `field-sizing: content`. When a text, select, or choice control matches `:user-invalid` or `[aria-invalid="true"]`, its border uses `--hue-danger`. Connect labels and hints with standard HTML `for`, `id`, and `aria-describedby` attributes.

Add `[checkbox]`, `[radio]`, `[switch]`, or `[range]` to style native inputs while keeping native control behaviour. `[checkbox]` supports both `:checked` and `:indeterminate` states. Set `--ui-range-fill` (default `0%`) on `[range]` to colour the filled track. Both `[switch]` and `[range]` reverse direction in right-to-left layouts. Under `prefers-reduced-motion: reduce`, control transitions are disabled. Under `forced-colors: active`, `[checkbox]`, `[radio]`, `[switch]`, and `[range]` revert to `appearance: auto`.

Wrap a `<label>`, a `[field-control]` container, and an optional `<small>` hint in `[field]`. Adding any non-neutral `[ui-tone]` to `<small>` or `<p>` colours the text with `--v2` both inside and outside `[field]`. Add `[field-inline]` to place a checkbox, radio, or switch beside its label with the hint underneath. A `<label>` inside `[field]` is dimmed when any descendant is `:disabled`. Use `[fieldset]` for a bordered `<fieldset>` and bold `<legend>`. Wrap adjacent `[btn]`, `[input]`, `[textarea]`, `[select]`, or static `[affix]` elements in `[group]` to join them with shared borders and outer corner rounding. Focusing an input inside `[group]` draws one `--ring` outline around the group container. Add `group-variant="inset"` to place a compact `[btn]` inside a single bordered input box (use `[cluster]` for separate controls).

```python
preview('''
<section card stack>
  <div field>
    <label for="name">Workspace name</label>
    <div field-control>
      <div group group-variant="inset">
        <input input id="name" value="Research" aria-describedby="hint">
        <button type="button" btn btn-variant="secondary">Save</button>
      </div>
    </div>
    <small id="hint">Shown to collaborators.</small>
  </div>
  <label><input checkbox type="checkbox" checked> Send a summary</label>
</section>
''', height='13rem')
```

## Surfaces, status, and tables

Add `[card]` for a raised `--color-surface` container with `--space` padding and a border. Combine `[card]` with `[stack]` or another layout attribute when you need spacing between its children. Add `[inset]` for a left-bordered panel for conditional form fields or callouts. Add `[badge]` for an inline status label tinted by the active `[ui-tone]`, or `badge-variant="secondary"` for a `--color-surface` badge with an inset border. Add `[avatar]` for a circular image or initials box sized by `--avatar-size` (default `2.5rem`). When `[avatar]` is the only child of `[btn]`, the button becomes a circular `1px`-padded `--color-surface` frame.

Use `[alert]` with `[ui-tone]` for persistent notices instead of transient button states. Inside `[alert]`, a direct child `[stack]` fills the remaining row width with `--space-2` gaps, and plain links inherit `--v2` contrast for error summary links. Add `[progress]` to style a native `<progress>` bar at full width with `--color-accent`. Add `[spinner]` to show a `1em` spinning indicator before its label. Under `prefers-reduced-motion: reduce`, the animation stops. Add `[skeleton]` for a full-width placeholder bar (`1em` high) in `--n-1`.

Add `[table]` to a `<table>` (`table[table]`) for row borders, start-aligned cells, bold headers and footer headings, and a bottom caption. Add `[num]` to numeric `<th>` and `<td>` cells for end alignment and tabular digits (`tabular-nums`). Wrap `table[table]` in `[table-frame]` for a bordered, horizontally scrolling container with `--color-surface` headers and `white-space: nowrap` cells. Give `[table-frame]` `role="region"`, `tabindex="0"`, and `aria-label` so keyboard users can scroll it. Plain `<table>` elements inside `[prose]` use the prose table styles instead. Add `summary-list` to a `<dl>` of `<div><dt>...</dt><dd>...</dd></div>` rows for a responsive key-value list with an optional trailing action `<dd>`.

```python
preview('''
<section stack>
  <div cluster><span badge ui-tone="success">Ready</span><span badge badge-variant="secondary">Shared</span></div>
  <div table-frame role="region" tabindex="0" aria-label="Usage">
    <table table>
      <caption>Processed requests this month</caption>
      <thead><tr><th scope="col">Workspace</th><th scope="col" num>Requests</th></tr></thead>
      <tbody><tr><td>Research</td><td num>119</td></tr><tr><td>Operations</td><td num>8</td></tr></tbody>
      <tfoot><tr><th scope="row">Total</th><td num>127</td></tr></tfoot>
    </table>
  </div>
</section>
''', height='16rem')
```
