---
title: "Icon Button · UI SDK — StyleX Blocks"
description: "Square and circular icon-only buttons sharing the Button recipe across all variants and control sizes."
url: "https://stylexblocks.com/components/ui-sdk/icon-button/"
agent:
  instructions: "Use this search API to find relevant components and blocks across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://stylexblocks.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Icon Button

Square and circular icon-only buttons sharing the Button recipe across all variants and control sizes.

- Behavior engine: UI SDK
- Also available for: [Ark UI](https://stylexblocks.com/components/ark-ui/icon-button.md), [Base UI](https://stylexblocks.com/components/base-ui/icon-button.md)
- Category: Form
- Variants: solid, subtle, surface, outline, ghost, plain
- Sizes: xs, sm, md, lg, xl
- Used in blocks: [AI Chat Conversation](https://stylexblocks.com/block/ui-sdk/ai-chat.md), [AI Chat Landing](https://stylexblocks.com/block/ui-sdk/ai-chat-landing.md), [Basic Login](https://stylexblocks.com/block/ui-sdk/basic-login.md), [Canvas Editor](https://stylexblocks.com/block/ui-sdk/canvas-editor.md), [Card Grid](https://stylexblocks.com/block/ui-sdk/card-grid.md), [Checkout Form](https://stylexblocks.com/block/ui-sdk/checkout-form.md), [Checkout Wizard](https://stylexblocks.com/block/ui-sdk/checkout-wizard.md), [Classic Gallery](https://stylexblocks.com/block/ui-sdk/classic-gallery.md), [Collapsible Table](https://stylexblocks.com/block/ui-sdk/collapsible-table.md), [Comparison Table](https://stylexblocks.com/block/ui-sdk/comparison-table.md), [Documentation Catalog](https://stylexblocks.com/block/ui-sdk/documentation-catalog.md), [Documentation Design](https://stylexblocks.com/block/ui-sdk/documentation-design.md), [Documentation Technical](https://stylexblocks.com/block/ui-sdk/documentation-technical.md), [File Explorer](https://stylexblocks.com/block/ui-sdk/file-explorer.md), [Filterable Table](https://stylexblocks.com/block/ui-sdk/filterable-table.md), [Dialog Wizard](https://stylexblocks.com/block/ui-sdk/form-wizard-dialog.md), [Funnel & Cohort Dashboard](https://stylexblocks.com/block/ui-sdk/funnel-cohort-dashboard.md), [Grouped Table](https://stylexblocks.com/block/ui-sdk/grouped-table.md), [IDE Workspace](https://stylexblocks.com/block/ui-sdk/ide.md), [Inbox Table](https://stylexblocks.com/block/ui-sdk/inbox-table.md), [Incident Console](https://stylexblocks.com/block/ui-sdk/incident-console.md), [Kanban Board](https://stylexblocks.com/block/ui-sdk/kanban-board.md), [Messaging Shell](https://stylexblocks.com/block/ui-sdk/messaging-shell.md), [Mixed Gallery](https://stylexblocks.com/block/ui-sdk/mixed-gallery.md), [Order Detail](https://stylexblocks.com/block/ui-sdk/order-detail.md), [Page Editor](https://stylexblocks.com/block/ui-sdk/page-editor.md), [Product Detail](https://stylexblocks.com/block/ui-sdk/product-detail.md), [Searchable Table](https://stylexblocks.com/block/ui-sdk/searchable-table.md), [Settings Dialog](https://stylexblocks.com/block/ui-sdk/settings-dialog.md), [Shell Nav](https://stylexblocks.com/block/ui-sdk/shell-nav.md), [Side Nav Shell](https://stylexblocks.com/block/ui-sdk/shell-side-nav.md), [Top Nav Shell](https://stylexblocks.com/block/ui-sdk/shell-top-nav.md), [Side Gallery](https://stylexblocks.com/block/ui-sdk/side-gallery.md), [Simple Table](https://stylexblocks.com/block/ui-sdk/simple-table.md), [Tree Table](https://stylexblocks.com/block/ui-sdk/tree-table.md), [Work Item Detail](https://stylexblocks.com/block/ui-sdk/work-item-detail.md)
- HTML page: https://stylexblocks.com/components/ui-sdk/icon-button/

## Install

Configure the project once (sets the behavior engine and import aliases):

```sh
npx stylexblocks init --style ui-sdk
```

Then add the item as source you own:

```sh
npx stylexblocks add icon-button
```

Equivalent: `npx shadcn add @stylexblocks/icon-button`. Registry item JSON: https://stylexblocks.com/r/ui-sdk/icon-button.json

## Usage

```tsx
import { IconButton } from "#components/ui/ui-sdk/icon-button.tsx";
import { indigoPalette } from "@stylexblocks/ui/themes/palettes.ts";

export function Example() {
  return (
    <>
      <IconButton variant="surface" size="md" aria-label="Search">
        <SearchIcon />
      </IconButton>

      <IconButton variant="solid" shape="rounded" palette={indigoPalette} aria-label="New item">
        <PlusIcon />
      </IconButton>
    </>
  );
}
```

## Source

`components/ui/ui-sdk/icon-button.tsx`

```tsx
import * as stylex from "@stylexjs/stylex";
import { Button as UiSdkButton } from "@ui-sdk/react/button";
import { createComponent } from "#lib/ui-sdk/create-component.tsx";
import { defineRecipe, fromMap } from "#lib/recipe-props.ts";
import { radii } from "@stylexblocks/ui/tokens/radii.stylex.ts";
import { buttonIconVars } from '@stylexblocks/ui/recipes/button.stylex.ts'

import { colorPalette } from '@stylexblocks/ui/color-palette.stylex.ts'
import { durations } from '@stylexblocks/ui/tokens/durations.stylex.ts'
import { fontWeights } from '@stylexblocks/ui/tokens/font-weights.stylex.ts'
import { semanticColors } from '@stylexblocks/ui/semantic-tokens/colors.stylex.ts'
import { semanticRadii } from '@stylexblocks/ui/semantic-tokens/radii.stylex.ts'
import { semanticShadows } from '@stylexblocks/ui/semantic-tokens/shadows.stylex.ts'
import { sizes } from '@stylexblocks/ui/tokens/sizes.stylex.ts'
import { spacing } from '@stylexblocks/ui/tokens/spacing.stylex.ts'
import { textStyles } from '@stylexblocks/ui/text-styles.ts'


const buttonStyles = stylex.create({
  base: {
    display: 'inline-flex',
    appearance: 'none',
    alignItems: 'center',
    justifyContent: 'center',
    userSelect: 'none',
    position: 'relative',
    whiteSpace: 'nowrap',
    verticalAlign: 'middle',
    cursor: {
      default: 'pointer',
      ':is(:disabled, [disabled], [data-disabled])': 'not-allowed',
    },
    flexShrink: 0,
    outline: 'none',
    lineHeight: 1.2,
    isolation: 'isolate',
    fontWeight: fontWeights.medium,
    transitionProperty:
      'background-color, border-color, color, fill, stroke, opacity, box-shadow, transform',
    transitionDuration: durations.moderate,
    outlineWidth: {
      default: null,
      ':focus-visible': '1px',
    },
    outlineOffset: {
      default: null,
      ':focus-visible': '2px',
    },
    outlineStyle: {
      default: null,
      ':focus-visible': 'solid',
    },
    outlineColor: {
      default: null,
      ':focus-visible': colorPalette.focusRing,
    },
    opacity: {
      default: null,
      ':is(:disabled, [disabled], [data-disabled])': 0.5,
    },
    [buttonIconVars.fontSize]: '1em',
    [buttonIconVars.flexShrink]: 0,
  },
})

const buttonSizes = stylex.create({
  '2xs': {
    gap: spacing._1,
    height: sizes.controlXs,
    minWidth: sizes.controlXs,
    borderRadius: semanticRadii.control,
    paddingInline: spacing._2,
  },
  xs: {
    gap: spacing._1,
    height: sizes.controlXs,
    minWidth: sizes.controlXs,
    borderRadius: semanticRadii.control,
    paddingInline: spacing._2,
  },
  sm: {
    gap: spacing._2,
    height: sizes.controlSm,
    minWidth: sizes.controlSm,
    borderRadius: semanticRadii.control,
    paddingInline: spacing._2_5,
  },
  md: {
    gap: spacing._2,
    height: sizes.controlMd,
    minWidth: sizes.controlMd,
    borderRadius: semanticRadii.control,
    paddingInline: spacing._3,
  },
  lg: {
    gap: spacing._3,
    height: sizes.controlLg,
    minWidth: sizes.controlLg,
    borderRadius: semanticRadii.control,
    paddingInline: spacing._4_5,
  },
  xl: {
    gap: spacing._3,
    height: sizes.controlXl,
    minWidth: sizes.controlXl,
    borderRadius: semanticRadii.control,
    paddingInline: spacing._6,
  },
})

const buttonVariants = stylex.create({
  solid: {
    backgroundColor: {
      default: colorPalette.solid,
      ':hover': `color-mix(in oklch, ${colorPalette.solid} 90%, transparent)`,
    },
    boxShadow: semanticShadows.sm,
    color: colorPalette.contrast,
  },
  subtle: {
    backgroundColor: {
      default: `color-mix(in oklch, ${colorPalette.solid} 10%, transparent)`,
      ':hover': `color-mix(in oklch, ${colorPalette.solid} 20%, transparent)`,
    },
    color: colorPalette.fg,
  },
  glass: {
    backgroundColor: {
      default: colorPalette.solid,
      ':hover': colorPalette.solid,
    },
    color: colorPalette.contrast,
    '--btn-shadow': semanticShadows.sm,
    boxShadow:
      'light-dark(0 0 0 1px rgba(0,0,0,0.25) inset, 0px 2px 0px 0px rgba(255,255,255,0.2) inset, var(--btn-shadow),  0px 1px 0px 0px rgba(255,255,255,0.2) inset, var(--btn-shadow))',
    textShadow: '0 1px 2px rgba(0,0,0,0.1)',
    overflow: 'clip',
    '::after': {
      content: '""',
      position: 'absolute',
      top: 0,
      left: 0,
      right: 0,
      bottom: 0,
      backgroundImage: {
        default: 'linear-gradient(180deg, white 40%, rgba(0,0,0,0.2))',
        ':hover':
          'linear-gradient(180deg, rgba(255,255,255,0.8) 40%, rgba(0,0,0,0.6))',
      },
      opacity: 0.2,
      transitionProperty: 'opacity',
      transitionDuration: durations.moderate,
      pointerEvents: 'none',
    },
  },
  surface: {
    backgroundColor: {
      default: semanticColors.bg,
      ':hover': colorPalette.muted,
    },
    borderWidth: '1px',
    borderColor: {
      default: `color-mix(in oklch, ${colorPalette.emphasized} 90%, transparent)`,
      ':hover': colorPalette.emphasized,
    },
    color: colorPalette.fg,
  },
  outline: {
    borderWidth: '0.5px',
    borderColor: colorPalette.emphasized,
    color: colorPalette.fg,
    backgroundColor: {
      default: null,
      ':hover': colorPalette.muted,
    },
  },
  ghost: {
    color: colorPalette.fg,
    backgroundColor: {
      default: null,
      ':hover': colorPalette.subtle,
    },
  },
  plain: {
    color: colorPalette.fg,
    paddingInline: 0,
  },
})

const buttonTextStyles = {
  '2xs': textStyles.xs,
  xs: textStyles.xs,
  sm: textStyles.sm,
  md: textStyles.sm,
  lg: textStyles.md,
  xl: textStyles.lg,
} as const

const buttonWhenVariantSurface = stylex.create({
  sm: {
    boxShadow: semanticShadows.xs,
  },
  md: {
    boxShadow: semanticShadows.sm,
  },
  lg: {
    boxShadow: semanticShadows.sm,
  },
  xl: {
    boxShadow: semanticShadows.md,
  },
})

const buttonIcon = stylex.create({
  base: {
    fontSize: buttonIconVars.fontSize,
    flexShrink: buttonIconVars.flexShrink,
  },
})

export type ButtonSize = keyof typeof buttonSizes

export type ButtonVariant = keyof typeof buttonVariants

const iconButtonSquare = stylex.create({
  "2xs": { width: sizes.controlXs, paddingInline: 0 },
  xs: { width: sizes.controlXs, paddingInline: 0 },
  sm: { width: sizes.controlSm, paddingInline: 0 },
  md: { width: sizes.controlMd, paddingInline: 0 },
  lg: { width: sizes.controlLg, paddingInline: 0 },
  xl: { width: sizes.controlXl, paddingInline: 0 },
});

const iconButtonShapes = stylex.create({
  square: {},
  rounded: { borderRadius: radii.full },
});

/**
 * IconButton — square icon-only button sharing the Button recipe across all
 * variants and control sizes, with optional circular (`shape="rounded"`)
 * geometry. Behavior comes from UI SDK's Button (Promise-pending and
 * `focusableWhenDisabled`). Always supply `aria-label` (or
 * `aria-labelledby`) for screen readers. Composition via `render`.
 */
const iconButtonRecipe = defineRecipe({
  styles: buttonStyles,
  axes: {
    variant: buttonVariants,
    size: buttonSizes,
    shape: iconButtonShapes,
  },
  defaultVariants: { variant: "ghost", size: "md", shape: "square" },
  extend: (v) => [
    buttonTextStyles[v.size],
    v.variant === "surface" && fromMap(buttonWhenVariantSurface, v.size),
    iconButtonSquare[v.size],
  ],
});

export const IconButton = createComponent(UiSdkButton, iconButtonRecipe, "IconButton");

export type IconButtonProps = React.ComponentProps<typeof IconButton>;
```
