IconButton
@codeui/solid v0.3.0
A named icon action for compact toolbars.
When to use
Use IconButton for a familiar action in a toolbar when a visible label would take too much space. Give every icon button an accessible name and a kit Tooltip.
When to choose another component
Use Link for inline navigation. Use Button when the action needs a visible label.
Live demo
import { IconButton, Tooltip } from "@codeui/solid";
export default function Demo() {
return (
<div style={{ display: "flex", "flex-wrap": "wrap", gap: "var(--cui-space-3)", "align-items": "center" }}>
<Tooltip content="Copy snippet"><IconButton variant="secondary" aria-label="Copy snippet" onClick={() => alert("Copy requested")}><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></IconButton></Tooltip>
</div>
);
}Anatomy
Tap a part to outline it in the demo.
- 01IconButton
iconbutton
| Export | Renders | classes key | data-cui | Role |
|---|---|---|---|---|
IconButton | button by default | None | iconbutton | Button |
IconButton delegates to Button and replaces its data-cui value. The icon is your child element.
Variants
Colors
import { IconButton, Tooltip } from "@codeui/solid";
export default function Demo() {
return (
<div style={{ display: "flex", "flex-wrap": "wrap", gap: "var(--cui-space-3)", "align-items": "center" }}>
<Tooltip content="Export PNG"><IconButton variant="primary" aria-label="Export PNG"><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></IconButton></Tooltip>
<Tooltip content="Copy snippet"><IconButton variant="secondary" aria-label="Copy snippet"><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></IconButton></Tooltip>
<Tooltip content="Share snippet"><IconButton variant="tertiary" aria-label="Share snippet"><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></IconButton></Tooltip>
<Tooltip content="Overwrite export"><IconButton variant="caution" aria-label="Overwrite export"><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></IconButton></Tooltip>
<Tooltip content="Delete snippet"><IconButton variant="negative" aria-label="Delete snippet"><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></IconButton></Tooltip>
</div>
);
}primary uses brand fill. secondary is neutral. tertiary uses soft brand fill. caution and negative use warning and danger colors. There is no default variant, so specify one.
Sizes
import { IconButton, Tooltip } from "@codeui/solid";
export default function Demo() {
return (
<div style={{ display: "flex", "flex-wrap": "wrap", gap: "var(--cui-space-3)", "align-items": "center" }}>
<Tooltip content="Copy snippet (xs)"><IconButton variant="secondary" size="xs" aria-label="Copy snippet (xs)"><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></IconButton></Tooltip>
<Tooltip content="Copy snippet (sm)"><IconButton variant="secondary" size="sm" aria-label="Copy snippet (sm)"><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></IconButton></Tooltip>
<Tooltip content="Copy snippet (md)"><IconButton variant="secondary" size="md" aria-label="Copy snippet (md)"><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></IconButton></Tooltip>
<Tooltip content="Copy snippet (lg)"><IconButton variant="secondary" size="lg" aria-label="Copy snippet (lg)"><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></IconButton></Tooltip>
</div>
);
}xs, sm, md, and lg are 28px, 36px, 44px, and 52px at comfortable density. The default is sm. Density adjusts the height without changing the font size.
Ghost
import { IconButton, Tooltip } from "@codeui/solid";
export default function Demo() {
return (
<div style={{ display: "flex", "flex-wrap": "wrap", gap: "var(--cui-space-3)", "align-items": "center" }}>
<Tooltip content="Copy snippet (primary)"><IconButton variant="primary" ghost aria-label="Copy snippet (primary)"><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></IconButton></Tooltip>
<Tooltip content="Copy snippet (secondary)"><IconButton variant="secondary" ghost aria-label="Copy snippet (secondary)"><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></IconButton></Tooltip>
<Tooltip content="Copy snippet (tertiary)"><IconButton variant="tertiary" ghost aria-label="Copy snippet (tertiary)"><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></IconButton></Tooltip>
<Tooltip content="Copy snippet (caution)"><IconButton variant="caution" ghost aria-label="Copy snippet (caution)"><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></IconButton></Tooltip>
<Tooltip content="Copy snippet (negative)"><IconButton variant="negative" ghost aria-label="Copy snippet (negative)"><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></IconButton></Tooltip>
</div>
);
}ghost removes the idle fill. The variant colors appear on hover.
Pill
import { IconButton, Tooltip } from "@codeui/solid";
export default function Demo() {
return (
<div style={{ display: "flex", "flex-wrap": "wrap", gap: "var(--cui-space-3)", "align-items": "center" }}>
<Tooltip content="Copy snippet"><IconButton variant="secondary" pill aria-label="Copy snippet"><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></IconButton></Tooltip>
</div>
);
}pill uses fully rounded corners.
Block
import { IconButton, Tooltip } from "@codeui/solid";
export default function Demo() {
return (
<div style={{ width: "100%" }}><Tooltip content="Copy snippet"><IconButton variant="secondary" block aria-label="Copy snippet"><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></IconButton></Tooltip></div>
);
}block sets width to 100% and flex to 1. Reserve full-width actions for layouts such as stacked phone controls. The square width rule can compete with block, so avoid full-width icon actions.
Render as a link
import { IconButton, Tooltip } from "@codeui/solid";
export default function Demo() {
return (
<div style={{ display: "flex", "flex-wrap": "wrap", gap: "var(--cui-space-3)", "align-items": "center" }}>
<Tooltip content="Open CodeImage"><IconButton as="a" href="https://codeimage.dev" variant="secondary" aria-label="Open CodeImage"><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></IconButton></Tooltip>
</div>
);
}as="a" accepts href and renders an anchor with button styling. An anchor with href retains native link semantics and uses Enter to follow the destination. Space does not activate an anchor. Use Link for ordinary navigation. A router component passed through as must forward the relevant props and ref.
States
Disabled
import { IconButton, Tooltip } from "@codeui/solid";
export default function Demo() {
return (
<div style={{ display: "flex", "flex-wrap": "wrap", gap: "var(--cui-space-3)", "align-items": "center" }}>
<Tooltip content="Copy snippet"><IconButton variant="secondary" disabled aria-label="Copy snippet"><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></IconButton></Tooltip>
</div>
);
}disabled disables a native button and removes it from the tab order. Non-native controls only receive aria-disabled and data-disabled. Kobalte does not add an activation guard or remove href from a button rendered as an anchor. Guard navigation and handlers yourself for that case.
Loading
import { IconButton, Tooltip } from "@codeui/solid";
export default function Demo() {
return (
<div style={{ display: "flex", "flex-wrap": "wrap", gap: "var(--cui-space-3)", "align-items": "center" }}>
<Tooltip content="Copy snippet"><IconButton variant="secondary" loading disabled aria-busy="true" aria-label="Copy snippet"><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></IconButton></Tooltip>
</div>
);
}loading places animated dots over the existing content without changing its dimensions. It sets data-loading and blocks pointer events through CSS.
It does not set disabled or aria-busy, and it does not prevent keyboard activation. Pair all three props while an action runs, as the example does.
Ready API
IconButton
IconButton renders a square Kobalte button through Button.
Prop
Type
The package root exports IconButton but does not export its props type. The table derives its props from the public component.
Inherited from Kobalte's button contract:
Prop
Type
Accessibility
Keyboard
| Key | Action |
|---|---|
| Tab or Shift+Tab | Moves focus between enabled controls. |
| Enter | Activates the focused button. |
| Space | Activates the focused button. |
ARIA
The default native element has button semantics. Kobalte supplies role="button" for non-native elements except anchors with href. It does not add keyboard activation handlers to arbitrary elements. Disabled controls expose data-disabled.
aria-label is required by the IconButton type. Name the action, such as "Copy snippet", rather than the icon shape. A tooltip does not replace this name. Hide decorative SVGs from assistive technology.
Loading adds an internal aria-label="Loading" span. It does not provide a live region. Supply status feedback outside the button when completion needs an announcement.
Focus
The button styles draw a focus-visible ring with the shared focus tokens. These controls do not open an overlay or move focus on their own. If your handler opens or closes an overlay, that overlay owns focus placement and restoration.
SSR notes
The root and its children render on the server. There is no portal or client-only mount step in IconButton.
Event handlers become active after hydration. Keep the initial props equal on the server and client.
The tooltip in the examples has its own client-side portal behavior.
Theming hooks
The shared button styles read these global variables. IconButton uses the same variables.
--cui-action-brand-{base,hover,active,text}for primary.--cui-action-neutral-{base,hover,active,text}for secondary and disabled controls.--cui-action-brand-soft-{base,hover,active,text}for tertiary.--cui-action-danger-{base,hover,active,text}for negative.--cui-action-caution-{base,hover,active,text}for caution.--cui-control-height-{xs,sm,md,lg}and--cui-font-size-{xs,sm,md,lg}.--cui-radius-{xs,sm,md,lg,xl,full},--cui-space-{1,2,4,5,6}, and--cui-font-weight-medium.--cui-border-width,--cui-text-default, and--cui-focus-{width,color,offset}.--cui-motion-duration-{fast,normal}and--cui-motion-ease-outfor transitions and the loading overlay.
Each brace expands to a separate variable. See Inkstone color and motion.
The local buttonStyles.buttonVars contract controls height, font size, fills, text color, border, padding, and radius.
Current kit sizes, borders, hover rules, and loading motion differ from parts of the Inkstone specification. These galleries document the shipped API.
Composition examples
import { IconButton, Tooltip, icons } from "@codeui/solid";
export default function Demo() {
return (
<div style={{ display: "flex", "flex-wrap": "wrap", gap: "var(--cui-space-3)", "align-items": "center" }}>
<Tooltip content="Previous snippet"><IconButton variant="secondary" aria-label="Previous snippet"><icons.PreviousIcon aria-hidden="true" /></IconButton></Tooltip>
<Tooltip content="Next snippet"><IconButton variant="secondary" aria-label="Next snippet"><icons.NextIcon aria-hidden="true" /></IconButton></Tooltip>
</div>
);
}Pair named icon actions with tooltips covering the whole hit area.
Related
- Button provides a visible action label.
- IconButton provides a compact named action.
- Link provides inline navigation.
- Tooltip explains an icon action on hover and focus.