Icon button

Free

An icon-only button in every style, that can hold on or off as a toggle (bold, italic, a thumbs up) and name itself in a tooltip with its key.

npx shadcn@latest add @pixilui/icon-button

Preview

A pressed toggle sets into the glass instead of changing color.
Show

When to use

Use it when

  • Actions whose icon is understood at a glance: close, more, attach, send.
  • Formatting toggles in an editor or composer: bold, italic, link. Feedback under an answer: good or bad response.
  • A dense row where text labels would crowd: name each one with a tooltip and its key.

Use something else when

  • An action whose icon needs explaining every time: use Button with a label.
  • Exactly one of several options: use the segmented control.
  • A row of tools on one tray with arrow-key movement: use Button group.

Installation

Terminal
npx shadcn@latest add @pixilui/icon-button

Adds icon-button.tsx with button.tsx and tooltip.tsx, and installs clsx, tailwind-merge and @base-ui/react. First PixilUI item in this app? Add the registry once, as in Installation.

Usage

example.tsx
import { IconButton } from "@/components/pixilui/icon-button";

<IconButton
  icon={icon}
  aria-label={aria-label}
  onPressedChange={onPressedChange}
  onClick={onClick}
/>

A square in quiet, a circle in lively, at the button's five sizes. Touch screens never show tooltips, so the name must not depend on one.

API reference

PropTypeDefault
iconRequiredReactNode–The icon (Lucide, or your own). Pass it as a node; the button sets its size and stroke.
aria-labelRequiredstring–The accessible name, and the tooltip's text unless tooltip says otherwise ("Attach files").
pressedLook"set" | "glyph"–How a pressed toggle looks: "set" (set into the surface, the default) or "glyph" (the icon fills, for feedback).
variantButtonVariant–Visual weight, as on Button: primary, secondary (the glass, default), secondary-2 (no fill until hover), danger.
sizeButtonSize–Height and width, as on Button: xs 24, sm 28, md 32 (default), lg 36, xl 44.
tooltipboolean | string–Show a tooltip on hover and focus: true uses aria-label, a string says something else.
shortcutstring–A key hint in the tooltip ("⌘U"). Needs tooltip.

Keyboard

TabMoves focus to the button; a tooltip, if it has one, opens on keyboard focus.
EnterActivates it, or turns a toggle on or off.
SpaceSame as Enter, on release.
EscCloses its tooltip and keeps focus on the button.

Accessibility

  • aria-label is required at the type level; it is also the tooltip's text unless tooltip names something else.
  • A toggle sets aria-pressed true or false and keeps the same name in both states ("Bold"). data-state is on or off.
  • The icon is aria-hidden; the shortcut in the tooltip is a hint, not part of the name.
  • Small sizes reach a 40px hit area on desktop and 44 on touch without growing.

Motion

  • Press scales to .96 in 150ms ease-out; a pressed toggle sets in (an inner shade, no lit top) on the same quick curve.
  • The glyph look fills the icon in 150ms. The tooltip waits once, then slides between neighbours.
  • Reduced motion: no press scale; state changes and the tooltip land at once.

PixilUI Pro opens Thu 10 Dec. The first 20 licenses are $99.